Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
26
rated 0 times [  30] [ 4]  / answers: 1 / hits: 95902  / 13 Years ago, fri, april 15, 2011, 12:00:00

I have a dropdown menu and I cannot figure out how to make a javascript function select a drop down menu option. I have tested the output of the variables and they are all correct, but it still will not select the option when clicked. Here is the function and drop down menu.



Function



function formFill(a, b, c){
theform.from.value = a;
theform.to.value = b;
for(var i = 0;i < document.getElementById(stateSelect).length;i++){
if(document.getElementById(stateSelect).options[i].value == c ){
document.getElementById(stateSelect).selected = true;
}
}
}


Menu item



<select id=stateSelect name=stateSelect>
<option value=none>(None)</option>
<option value=AL>Alabama</option>
<option value=AK>Alaska</option>

More From » html

 Answers
5

Change the line that reads:



document.getElementById(stateSelect).selected = true;



to:



document.getElementById(stateSelect).selectedIndex = i;


[#92706] Thursday, April 14, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
alexander

Total Points: 693
Total Questions: 114
Total Answers: 95

Location: Indonesia
Member since Wed, Jul 7, 2021
3 Years ago
;