Forum Moderators: open
I'm trying to change the selected index of a drop down menu based on the value of a <span> tag but it doesn't work for me. I might be going about this entirely the wrong way so I thought I'd check. Heres what I have at the moment
switch(name){ case "John": jsidvalue=0; break; case "Jack": jsidvalue=1; break; } formElements.elements[i].selectedIndex = jsidvalue;
Its part of a loop that updates the entire form based on innerHTML of <span>s. All the input boxes update but drop downs don't.
alert("Find #" + name + "#");
switch(name){
case "John":
jsidvalue=0;
break;
case "Jack":
jsidvalue=1;
break;
}
alert("jsidvalue = " + jsidvalue);
formElements.elements[i].selectedIndex = jsidvalue;
Should I have the name of the form as <form name="formName"> or as <form id="formName">?
Heres what I have:
document.formName.formElemnt;<form id="formName">
<select id="formElement>
<option>1</option>
<option>2</option>
</select>
</form>
PS. If the code doesn't display as code this time its not my fault!:)
If you don't have the form Name, but you use id="formID" then you use document.getElementById("formID").
you can add a name="FormName" which almost always is the same as the id attribute.
If your not using the name attribute, you can use:
myFormElem = document.getElementById("formElement")
The rest should work as is.