Vega Discoveries Forum

Welcome Guest Search | Active Topics | Log In | Register

HTML select Get Value and Get Text Options
TechGuy
#1 Posted : Monday, February 01, 2010 12:33:34 PM
Rank: Advanced Member

Groups: Registered, Administrators

Joined: 8/17/2009
Posts: 43
It seems it is always the simple things that get forgotten!

I needed to be able to access the value and the text of the selection from a list.
This was the simple result:

Code:

<select id="Select1" name="D1" onchange="alert(this.value + ' ' + this.options[this.selectedIndex].text);">
    <option value="1">one</option>
    <option value="2">two</option>
    <option value="3">three</option>
</select>


Javascript exposes the text very nicely.
saviola
#2 Posted : Sunday, June 13, 2010 9:35:42 AM
Rank: Welcome Guest

Groups: Registered

Joined: 6/13/2010
Posts: 4
Location: Bulgaria
Also, in this case you can do this :

Code:
<script type="text/javascript">
function get(){
var val = document.getElementById('Select1').value;
var txt = document.getElementById('Select1').options[val-1].text;
alert(val +" - "+ txt);
}

</script>


Code:
<html>
<select id="Select1" name="D1" onchange="get();">
    <option value="1">one</option>
    <option value="2">two</option>
    <option value="3">three</option>
</select>
</html>
Nothing's imposible imagination is everything!
Database Benchmark Software (GNU GPL) | World's fastest database
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Vega Discoveries Theme Created by Richard Hancock (aka-Tech Guy) (Home Page)
Powered by YAF 1.9.3 | YAF © 2003-2009, Yet Another Forum.NET
This page was generated in 0.060 seconds.