Click to See Complete Forum and Search --> : Select item in combo box


kyberspace
09-05-2003, 05:18 PM
I have a page that calls up an item for a user to edit. Included is a combo box that lists different categories.

How do I set the selected property of that combo box to whatever is already in that field for the record?

For example, let's say the user selected "computer" from among the choices in the combo box when he originally added the item. When someone goes back to edit the item, how do I make the combo box automatically select "computer"?

Jona
09-05-2003, 07:15 PM
Your best bet is to go server-side with this and use a database to include the "selected" attribute of a specific option (in this case, "computer") since the user would need to be logged in. But in any case, this is the code that you would use to select the second option in a select box.


<script type="text/javascript"><!--
function select2(f){
f.sel.options[1].selected=true;
}
//--></script></head>
<body onload="select2(document.forms[0]);">
<form action=""><div>
<select name="sel">
<option value="-1">--SELECT--</option>
<option value="computer">Computer</option>
</select>
</div></form>
</body></html>


[J]ona