Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jun 2005
    Posts
    153
    Thanks
    26
    Thanked 0 Times in 0 Posts

    Preselected option in <select>

    Hello Everyone,

    I know that I can have the code:

    Code:
    <select name=test>
    	<option value="1">test1</option>
    	<option value="2" selected>test2</option>
    	<option value="3">test3</option>
    </select>
    However, is it possible to have the selected option in the <select> tag?

    Code:
    This Does Not Work
    <select name=test selected="a2">
    	<option value="1">test1</option>
    	<option value="2">test2</option>
    	<option value="3">test3</option>
    </select>
    Thanks

  • #2
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    No that causes invalid markup.
    jeremy - gnomeontherun
    Educated questions often get educated answers, and simple questions often get simple answers.

  • #3
    Regular Coder thesmart1's Avatar
    Join Date
    Dec 2005
    Posts
    369
    Thanks
    7
    Thanked 3 Times in 3 Posts
    Well, you could do this with JavaScript (see this site).

    But why do you want to adjust the selected option in the "select" tag? What's wrong with just using the "selected" attribute in the "option" tag?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •