Can we add custom attribute in a input tag

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • newlearner
    New Member
    • May 2007
    • 67

    Can we add custom attribute in a input tag

    Hi,
    Can an custom attribute be added into a input tag, apart from the predefined one

    <td ><button type="button" title="title" onclick="myFunc tion()" name="Name" ><span>OK</span></button></td>

    my button is as above is there any way that i can include another custom attribute to this.


    in advance......
    Thanks for your reply
  • dmjpro
    Top Contributor
    • Jan 2007
    • 2476

    #2
    Originally posted by newlearner
    Hi,
    Can an custom attribute be added into a input tag, apart from the predefined one

    <td ><button type="button" title="title" onclick="myFunc tion()" name="Name" ><span>OK</span></button></td>

    my button is as above is there any way that i can include another custom attribute to this.


    in advance......
    Thanks for your reply

    Yes why not?
    Of course u can.
    Look at this code carefully ...

    [code=javascript]
    //All the elements r in document .... object reference.Right ?
    var obj_ref = new Object();
    obj_ref.custom_ attr = ur_some_value; //Right?
    alert(obj_ref.c ustom_attr); //It ll not return undefined.Right ?
    [/code]

    Have a good day.

    Kind regards,
    Dmjpro.

    Comment

    • gits
      Recognized Expert Moderator Expert
      • May 2007
      • 5390

      #3
      yep ... you may add custom-attributes, and in my opinion it is the best way to do a lot of things where you have to have more then an id or name or other standard-attribs for an element. of course your may misuse other (standard) attributes ... class is a real good candidate for this ... and you may build some combined attribute-values that you use later on ... something like that:

      Code:
      // part1 ... to 3 is used later on seperately
      <tagname ... class="part1_part2_part3"/>
      but as the example shows, i think this will break the semantics of your code ... until you really need 3 attributes for the element you shouldn't be forced to combine them and set it as one value to an attribute, that has an other purpose.

      But! there is a drawback of using custom attributes ... they make your (x)html invalid ... when checking against a DTD or XML-schema ... and may be your attributes may interfere with future versions of HTML-implementations ... so use attr-names that are not common ... Browsers don't bother about custom attributes even when the page is invalid ... it has to be wellformed ... and validity is an add-on ... and as i said ... i always would prefer the custom-attr-way instead of misusing standard-attributes

      kind regards ...

      Comment

      • newlearner
        New Member
        • May 2007
        • 67

        #4
        Originally posted by gits
        yep ... you may add custom-attributes, and in my opinion it is the best way to do a lot of things where you have to have more then an id or name or other standard-attribs for an element. of course your may misuse other (standard) attributes ... class is a real good candidate for this ... and you may build some combined attribute-values that you use later on ... something like that:

        Code:
        // part1 ... to 3 is used later on seperately
        <tagname ... class="part1_part2_part3"/>
        but as the example shows, i think this will break the semantics of your code ... until you really need 3 attributes for the element you shouldn't be forced to combine them and set it as one value to an attribute, that has an other purpose.

        But! there is a drawback of using custom attributes ... they make your (x)html invalid ... when checking against a DTD or XML-schema ... and may be your attributes may interfere with future versions of HTML-implementations ... so use attr-names that are not common ... Browsers don't bother about custom attributes even when the page is invalid ... it has to be wellformed ... and validity is an add-on ... and as i said ... i always would prefer the custom-attr-way instead of misusing standard-attributes

        kind regards ...


        Thaks for the reply .....
        Finally i got it working

        Comment

        • newlearner
          New Member
          • May 2007
          • 67

          #5
          custom attribute is not recognised by firefox

          hi,
          below is my button

          <td><button type="button" custom="custom" title="title" onclick = "myFunction()"> </button></td>

          in javascript on click
          i say
          if(custom){aler t("Got IT !!!")}

          This works well with IE but not with firefox.

          Thaks for the reply in advance.

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            Merged threads because they were on the same topic.

            Comment

            Working...