Thursday, September 10, 2009

Set the value of combobox in javascript, set the value of html select value in javascript

Problem: Set the value of a combobox in javascript
Solution: For combobox give the values and names.
for ex:


Screenshot:
Javascript code to set the value of combobox:
document.forms[0].Combo.value="Test2";
i put the above code in Onload of the body. so by default the combo box value is "Test2".
The above code should work 99%. If the above javascript code is not working then use this:
for (var i=0; i (lessthan symbol here) document.forms[0].Combo.length; i++) {
if (document.forms[0].Combo[i].value == "Test2") {
document.forms[0].Combo[i].selected = true;
}
}




1 comment:

Search This Blog