homepage Welcome to WebmasterWorld Guest from 54.166.108.167
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
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




msg:583870
 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




msg:583871
 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




msg:583872
 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




msg:583873
 6:02 pm on Nov 6, 2003 (gmt 0)

This should work for xhtml:
selected="selected"

mcfly




msg:583874
 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