Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select Menu Default Not Working

Status
Not open for further replies.

uniopp

Technical User
Oct 7, 2001
152
JP
I'm using a php script to generate some html form pages and I'm having a strange problem
with the select menus. The default value is not being selected. The code I am using is -

<select name="test" id="test">
<option value="">Select</option>
<option value="One" selected>One</option>
<option value="Two">Two</option>
<option value="Three">Three</option>
</select>

This does not generate the same source code and "Select" is selected on the page generated by the browser
instead of "One".
The browser source code looks like this (notice the space where the word "selected" should appear)

<select name="test" id="test">
<option value="">Select</option>
<option value="One" >One</option>
<option value="Two">Two</option>
<option value="Three">Three</option>
</select>

I've tried numerous different things including using selected="selected" but the only thing that seems
to work is using the following (notice I have deleted the space before the word "selected")

<select name="test" id="test">
<option value="">Select</option>
<option value="One"selected>One</option>
<option value="Two">Two</option>
<option value="Three">Three</option>
</select>

This generates the same source code and "One" is selected on the page generated by the browser as it should be.

Does anyone know what the problem is and why it is not occurring on all select menus, only on some.
Thanks.
 
Whatever it is, it has to do with your php script. The HTML behaves as it should -- when selected="selected" (which is the best and recommended way of using it) is present, that option appears as selected and when not, it is the first one. Whatever happens between your php script and final HTML output is what is messing up your code.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top