views:

57

answers:

2

How do you get the selected option to be in view on page load?

<select name="whatever" size="5">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7" selected>7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
</select>

A: 

If I understand you correctly, you want the item shown in the dropdown list to be the selected item when the page loads. By default behavior the selected view does in fact show "in view" on page load. What are you seeing that you do not expect?

note: your html should be

<option value="7" selected="selected">7</option>

to be a valid html tag.

Jeremy B.
joe
Actually, `<option value="7" selected>` is correct; `selected="selected"` should only be used in XHTML.
Kevin Reid
A: 

All browsers I've tested (Firefox, Chrome, Opera and IE7) scroll the contents to display the selected option.

Edit: Windows XP

Álvaro G. Vicario
joe