AP257 AP257 - 2 months ago 10
HTML Question

Set value of select element based on GET parameters, without JavaScript?

Here's a very basic HTML question for you:

<form method="get" action="#">
<select id="u" name="u">
<option value="nothing" title=""></option>
<option value="AdamT" title="AT">Adam Temple</option>
<option value="AlexP" title="AP">Alex Potts</option>
</select>
<INPUT TYPE="submit" />
</form>


After submitting the form, the URL ends
?u=AdamT
. However, the list has reverted to the blank element.

Is there any way I could make the list be pre-selected with the correct option, without using JavaScript?

Answer

Add selected (its a boolean attribute) to the appropriate <option> element in whatever server side language you use to process the form.