I’m required to use Firefox 1.5 (yes I know…) for an in house tool, only used on a closed system.
I have a basic html select drop down menu:
<select name="selectName" ID="Select">
<option value="A" selected>Tom</option>
<option value="B">Jim</option>
<option value="C">Nancy</option>
</select>
In JavaScript, I would like to extract the name (inner text) of the selected option.
In Firefox 3.6 I can do the following:
var x = document.getElementById("Select");
var name = x.children[x.selectedIndex].text;
and name will contain the string of the selected drop down. (Tom by default)
However, when I run this code in Firefox 1.5, I get the following error:
x.children has no properties
Unfortunately, I can’t install Firebug on 1.5, as it is not compatible, to get any more information.
I have a JavaScript Error console on 1.5 and that is all.
How else can I get the text of the selected option, that would work with FF1.5.
Is there a JQuery method that would work in this situation?
Also, I’m interested why this does not work in FF1.5
(Is there a compatible JS debugger for FF 1.5?)
Thank You.
The
<select>element has an “options” attribute whose value is the array of<option>elements. You should be able to use that exactly as you’re using “children”. (In fact I think that’s a better habit to be in, because the children of the<select>aren’t necessarily just<option>elements.)