View Full Version : setting a <select> field automatically to a value

01-20-2005, 01:21 PM

im desperately trying to set a <select> field to a specific value.

Im loading all contents (<option>) of the select-field from a db.
Im loading another value from database as well.

With having the <select> field filled with the values from the first db-query -> e.g. Berlin,Munisch,London,Paris
and the result of the second db-query being London, i now want to set the select field to the third <option> which already is Londondon in the list.

I tried serveral ways with javascript via selected, selectedIndex and options[x] - but cant really figure out a way to solve this.

Thanks a lot for any help or tips on this problem !


01-20-2005, 01:40 PM
well, you could do <option value="blah" selected>(handled by server-side) ..
for JS to set the selected you could do it two ways..

object.options[2].selected = true;
object.selectedIndex = 3;

if that didn't help.. post some code.