Computer problems,Computer help
*AX SOFT>>>Programming & Design

How can I get the value inside an <option></option> tag on a select box using javascript?


I know how to get the value, but I don't know how to get the value inside the <option> tag. example:

<select>
<option vlaue="100">Option label</option>
</select>

I know how to get the "100" value, but not the "Option label" value.

Thx

Use the DOM! :)

<script type="text/javascript">
var sel = document.getElementById("MySelectBox")
var optVal = sel.options[<position of option, base 0>].text
</script>

--Example--
<select id="MySelectBox">
<option value="1">I'm the first option!</option>
<option value="3" selected>I'm the second option, and I'm selected!</option>
</select>

<script type="text/javascript">
var sel = document.getElementById("MySelectBox");
var pos = sel.selectedIndex;
var optText = sel.options[pos].text;
</script>

var ctrl = document.getElementById('control_id_here...
var indx = ctrl.selectedIndex;
var result = "";

if(indx > -1)
{
result = ctrl.options[indx].text;
}

Tags
  General - Computers & Internet   Software   Security   Programming & Design   Facebook   Flickr   Google   MSN   MySpace
Related information
  • Is there a service where i can create my own Im system?

    Yes, you could host your own Jabber instant messaging server (see ...

  • Align Text ?

    You may have whitespace appearing in your code or a line break of some kind. Really need to see the code you used. As a safety note, not a good idea to put personal information on a web page......

  • Whats wrong with this php code?

    Take out the # before $fp You need to escape those single quotes in the 'echo' at the end, also I don't know what the () is for.....try this: echo "your post was posted su...

  • How can I learn how to build wire frames?

    For anything you want to know about 'how to', just type the question into your Google slot - how to make wire frames : - how to make wireframes & schematics - Scifi-Meshes.com Hi...

  • How do I use footnotes on microsoft word?

    Word has a very good footnote system that will automatically maintain the numbering sequence no matter what you do to the footnotes. It will also do its darnedest to keep the footnotes on the page...

  • Hai guys i'm doing a project in C++.i want to know how to update the contents of a file in c++.?

    If you mean updating the data that is already in the file (for instance, changing a word in the file to another word), then you'll need to open the file for reading, read the whole file into a...

  • How to smooth this 3ds max model?!?

    Usually you get the best results from NURMS ("non-unified rational meshsmooth") Apply the Meshsmooth modifier and under 'method' choose 'NURMS'. You can increase the...

  • Anyone know anything about this company?

    Not much to do with programming :S

    ...
  •  

    Categories--Copyright/IP Policy--Contact Webmaster