www.webdeveloper.com
Results 1 to 5 of 5

Thread: [RESOLVED] .defaultValue for a dropdown?

  1. #1
    Join Date
    May 2009
    Posts
    2

    resolved [RESOLVED] .defaultValue for a dropdown?

    I'm relatively new to javascript. I know you can find the default (original) value of a text input field by using this.defaultValue. Is there an equivalent property for a dropdown list (<select><option>), or radio button list or checkbox list? .defaultValue doesn't seem to work.

    I can simply add a hidden field to keep track of the value but I'm not sure if there is a better way to do it.

  2. #2
    Join Date
    Oct 2006
    Posts
    93
    Radio & Checkbox = defaultChecked
    Doesn't look like drop down list has one.

    Not sure if this is what you are looking for, because I think this will only tell you if any individual input was checked or not, not for the entire group what was checked. Could be wrong on this though.

  3. #3
    Join Date
    May 2009
    Posts
    150
    Just save the select tag's value when the page first loads:

    Code:
    var selectDefault = selectTag.value;
    Then you can use that later, even if it changes:

    Code:
    if (selectTag.value != selectDefault) // Value has changed

  4. #4
    Join Date
    May 2009
    Posts
    12
    Are you talking about the "selected" option in a droplist?

    Like..

    PHP Code:
    <select name="dropList">
    <
    option value="DefaultValue" selected>Default Item</option>
    <
    option value="AnotherValue">NOT Default Item</option>
    </
    select

  5. #5
    Join Date
    May 2009
    Posts
    2

    resolved

    Thank you both for your replies. You pointed me in the right direction.
    There is a defaultSelected property for <option> elements, similar to defaultChecked for radio buttons and checkboxes. But there doesn't appear to be any property to get the value of the collective group of elements (i.e. selectTag.defaultSelected).
    I can either loop through the elements or just store the value somewhere, like a hidden field or a var like Y_Less suggested.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles