shinjuo shinjuo - 7 months ago 26
HTML Question

Select dropdown menu option with javascript

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 formFill(a, b, c){
theform.from.value = a; = 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>


Change the line that reads:

document.getElementById("stateSelect").selected = true;


document.getElementById("stateSelect").selectedIndex = i;