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 2 of 2
  1. #1
    Regular Coder
    Join Date
    Nov 2002
    Posts
    672
    Thanks
    1
    Thanked 1 Time in 1 Post

    "selected" attribute problems in <option>

    I've tried in IE and Firefox and this attribute works in neither one for <option> tags. According to the W3C you can assign a "selected" attribute to options in a <select> dropdown in order to force a certain value to be pre-selected when the page loads. But what happens is that the browser will show the selected value for the first time, but then when you refresh, it will be at the value that you left it at rather than the selected option in the dropdown (for example, if you refresh the page, it will at the value you left it at rather than what you used.

    Code:
    <form action="">
    <select>
    <option value="0">Default</option>
    <option value="1" selected="selected">Selected option</option>
    </select>
    </form>
    I have found that resetting the form on page load works, although it's not visually appealing. But for sake of javascript, rather than depending on a preset option matching a pre-selected value, it's better to get the value of the selected option (regardless of how it became selected, whether it be pre-selected or from the browser cache bug), and use it as a function argument. Was this problem intentional or unexpected?

  • #2
    New Coder
    Join Date
    Jun 2005
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Works in Safari

    Does it matter if you make it a list instead of a menu? i.e.
    <select size="1">


  •  

    Posting Permissions

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