Detecting default and current value with Select

S

Siah

Hi,

It's a mess. After an hour of hacking the closest I could get to
detecting the current value (Not key, but value) of select statement
that works both in Firefox and IE is :

selectElem.options[selectElem.selectedIndex].firstChild.nodeValue

Which is SICK, but I would be more than happy with it, except @ %$*@
Internet Explorer selectElem.selectedIndex is somehow always 0 (ZERO).
Now, for my purpose, I am desprate enough to accept just getting the
default (initially 'selected') index of my drop down (select). Is there
anyway to do that?

Please help,
Pissed Sia
 
M

Matt Kruse

Siah said:
It's a mess. After an hour of hacking the closest I could get to
detecting the current value (Not key, but value) of select statement
that works both in Firefox and IE is :
selectElem.options[selectElem.selectedIndex].firstChild.nodeValue
Which is SICK

Indeed, when
selectElem.options[selectElem.selectedIndex].text
would have worked just fine.
Internet Explorer selectElem.selectedIndex is somehow always 0 (ZERO).

In a multiple-select, perhaps.
Now, for my purpose, I am desprate enough to accept just getting the
default (initially 'selected') index of my drop down (select). Is
there anyway to do that?

Yes, loop through the options and find the one (or more) with
..defaultSelected==true.

Or, use a pre-written lib which does all this "mess" for you:
http://www.javascripttoolbox.com/lib/validations/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top