#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2012
    Posts
    2
    Rep Power
    0

    Add any custom attributes to input element


    Can I add any custom attributes on an input element?
    so If I have a regular checkbox

    Code:
    <input type='checkbox' name='mycheckbox1' > my checkbox
    be able to add attributes to use in javascript. Such as


    Code:
      <script language='javascript'>
    function doIt2(formname) {
      alert (formname.mycheckbox1.special);
    }
    </script>
      </head>
      <body>
    
    <input type='checkbox' name='mycheckbox1' special='xxxxx' onclick="doIt2(this)"> my checkbox 
       
      </body>
    </html>
    However this throws an error.
    Is something like this possible?

    thanks
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2008
    Posts
    129
    Rep Power
    12
    html5 has a new data attribute that allows for custom attributes without throwing errors. http://www.javascriptkit.com/dhtmltutors/customattributes.shtml

    it would be good to know that you can do it the way you are. The only errors you should be getting are from validators but that doesn't mean it won't work.

IMN logo majestic logo threadwatch logo seochat tools logo