Log in

View Full Version : How to set the selection of a combo list


xuanmanh
May 22, 2006, 03:02 AM
Does anyone know wherer there is a javascript method to set the selection of a combo list?

LTheobald
May 22, 2006, 04:49 AM
Something like this maybe...

Imagine you had the following list:


<select name="testselect">
<option value="first">first option</option>
<option value="second">second option</option>
<option value="third">third option</option>
</select>


You could then have a function like below:


function selectMe(val) {
for (var i=0; i<document.all.testselect.length; i++) {
if (document.all.testselect.options[i].value == val) {
document.all.testselect.options[i].selected = true;
}
}
}


So if you called selectMe with a value of "second", it would select the second option in the dropdown.

Is that what you meant?

xuanmanh
Jun 1, 2006, 04:59 AM
Yes, absolultely right, My problem was solved so well. Thank you very much