SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,235
    Mentioned
    154 Post(s)
    Tagged
    0 Thread(s)

    Data Attributes on INPUT tags

    Okay, first off, are the HTML 5 data attributes allowed on input tags? Every example I see, shows them on non-form related tags.

    The reason I ask, is jquery doesn't return the data attribute value of my form elements as shown here

    I should note that using
    Code:
    $('input:first').attr('data-originalValue');
    does retrieve the value

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    If you're wanting the default value of the input field, that is a property, not an attribute. The property is called defaultValue.

    So in that case, you could use something like:

    Code javascript:
    $('input:first').prop('defaultValue');
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,235
    Mentioned
    154 Post(s)
    Tagged
    0 Thread(s)
    Unfortunately, that doesn't seem to work for checkboxes/radio buttons. Regardless of the status (checked/unchecked), it returns the value. That does seem to work fine for text fields.

  4. #4
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,235
    Mentioned
    154 Post(s)
    Tagged
    0 Thread(s)
    Nevermind, I just saw I am to use defaultChecked instead of defaultValue on radio/checkboxes. prop should work, so long as I can update the value

  5. #5
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by cpradio View Post
    Unfortunately, that doesn't seem to work for checkboxes/radio buttons. Regardless of the status (checked/unchecked), it returns the value. That does seem to work fine for text fields.
    The defaultValue isn't used with checkboxes or radio buttons. It's a text field that is just not suitable for those types of fields.

    The jQuery prop() documentation page says that there is a defaultChecked property though, which seem like a much better candidate for your intended usage.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

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