PDA

View Full Version : Preselected option in <select>



questionable
10-24-2007, 11:10 PM
Hello Everyone,

I know that I can have the code:


<select name=test>
<option value="1">test1</option>
<option value="2" selected>test2</option>
<option value="3">test3</option>
</select>

However, is it possible to have the selected option in the <select> tag?


This Does Not Work
<select name=test selected="a2">
<option value="1">test1</option>
<option value="2">test2</option>
<option value="3">test3</option>
</select>

Thanks

gnomeontherun
10-24-2007, 11:53 PM
No that causes invalid markup.

thesmart1
10-26-2007, 02:58 AM
Well, you could do this with JavaScript (see this site (http://www.mredkj.com/tutorials/tutorial003.html)).

But why do you want to adjust the selected option in the "select" tag? What's wrong with just using the "selected" attribute in the "option" tag?