We help IT Professionals succeed at work.

Select Display Text Question

erzoolander
erzoolander asked
on
Medium Priority
162 Views
Last Modified: 2012-08-13
Hi -

We have a form with several SELECT form items within it.  We also have a javascript function that changes the selected index based upon certain criteria...   For example...

document.getElementById("state").selectedIndex = 0;
document.getElementById("region").selectedIndex = 0;

Now - the function works...as in it sets the selected index to 0 - but the option value does not update.  So - Say for State I choose...  "California" with a value of 5.  When I reset the value to 0 - it still shows "California" (which it shouldn't) - but the index HAS been changed to 0.

Is there something additional I'm missing - like selectedIndex.text or something?  or... document.getElementById("state").text?

Thanks!
Comment
Watch Question

F IgorDeveloper

Commented:
Try this (setting up the value property based on index):

var state1=document.getElementById("state");
state1.value=state1.options[0].value;
Top Expert 2013
Commented:
You need to set the selected attribute:

x=document.getElementById("state");
x.option[0].selected='selected';

Explore More ContentExplore courses, solutions, and other research materials related to this topic.