homepage Welcome to WebmasterWorld Guest from 23.23.9.5
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / HTML
Forum Library, Charter, Moderators: incrediBILL

HTML Forum

    
HTML select box default value
Can it be set to a specific option?
mcfly

10+ Year Member



 
Msg#: 6558 posted 5:02 pm on Nov 6, 2003 (gmt 0)

Hi everyone,

Does anyone have any idea whether it's possible to set a default option for an html drop-down select box?

I have an ordered set of options, but would like to highlight an option as a default without necessarily having it first in the list. I had a faint recollection of it being as simple as

<option value="x" default>x</option>

but it doesn't seem to work (at least not for Mozilla anyway), so I must be wrong on that.

For a bonus point, is there a way to do it for 'select multiple' form elements?

Thanks in advance!

 

korkus2000

WebmasterWorld Senior Member korkus2000 us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 6558 posted 5:58 pm on Nov 6, 2003 (gmt 0)

I believe selected instead of default should work. XHTML uses the nonshort-hand version, which I cannot remember off-hand.

pete_m

10+ Year Member



 
Msg#: 6558 posted 6:00 pm on Nov 6, 2003 (gmt 0)

You're right - it is easy.
Try
<option value="x" selected="selected">x</option>
which is XHTML compliant.

For multiple selectboxes just use the selected="selected" attribute for each option you need selected by default.

robjones

10+ Year Member



 
Msg#: 6558 posted 6:02 pm on Nov 6, 2003 (gmt 0)

This should work for xhtml:
selected="selected"

mcfly

10+ Year Member



 
Msg#: 6558 posted 6:56 pm on Nov 6, 2003 (gmt 0)

'selected="selected" ' works a treat.

Thanks for your help guys.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / HTML
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved