473,395 Members | 1,668 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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="myFunction()" 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
Jun 6 '07 #1
5 10550
dmjpro
2,476 2GB
Hi,
Can an custom attribute be added into a input tag, apart from the predefined one

<td ><button type="button" title="title" onclick="myFunction()" 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 ...

Expand|Select|Wrap|Line Numbers
  1. //All the elements r in document .... object reference.Right?
  2. var obj_ref = new Object();
  3. obj_ref.custom_attr = ur_some_value; //Right?
  4. alert(obj_ref.custom_attr); //It ll not return undefined.Right?
  5.  
Have a good day.

Kind regards,
Dmjpro.
Jun 6 '07 #2
gits
5,390 Expert Mod 4TB
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:

Expand|Select|Wrap|Line Numbers
  1. // part1 ... to 3 is used later on seperately
  2. <tagname ... class="part1_part2_part3"/>
  3.  
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 ...
Jun 6 '07 #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:

Expand|Select|Wrap|Line Numbers
  1. // part1 ... to 3 is used later on seperately
  2. <tagname ... class="part1_part2_part3"/>
  3.  
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
Jun 6 '07 #4
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){alert("Got IT !!!")}

This works well with IE but not with firefox.

Thaks for the reply in advance.
Jun 6 '07 #5
acoder
16,027 Expert Mod 8TB
Merged threads because they were on the same topic.
Jun 6 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: F. Da Costa | last post by:
Hi, I was wondering *why* there is a difference between the results of the following two statements. On the suface they seem to do the same (or do they?) frm => returns void ...
3
by: Edward Diener | last post by:
I understand the syntax of custom attributes, but I have no idea what they are supposed to do. Anyone care to give me a clue as to their functionality ?
21
by: One Handed Man \( OHM - Terry Burns \) | last post by:
When using a custom control. In order to check and see if values have changed one has to implement the IPostBackDataCollection interface. The values returned for the control seem to be simply a...
1
by: Chris Newby | last post by:
I have a custom control that derives from the WebControls.Panel class. In a given ASPX document, I have an instance of my custom control with ID set to "MyControl". Then I put a...
3
by: The Developer | last post by:
Hi All, I have a web application where I am adding a custom attribute to my ASP.NET text box control and changing value of that attribute at client side using JavaScript. My problem is that...
3
by: Mark R. Dawson | last post by:
Hi all, I am trying to get custom attributes from a property. I can do this if I pass in the name of the property i.e. "Name" to the reflection methods, but if I pass in set_Name which is what...
2
by: prabhupr | last post by:
Hi Folks I was reading this article (http://www.dotnetbips.com/articles/displayarticle.aspx?id=32) on "Custom Attribute", written by Bipin. The only thing I did not understand in this article...
0
by: webmaster | last post by:
Hi all, I'm tearing my hair out with this one. I have successfully implemented by own RadioButtonList in order to provide additional functionality and a DIV rather than TABLE-based layout in...
2
by: P4trykx | last post by:
Hello I'm want to add some custom attributes to WebControls using WebControl.Attributes.Add("abc","234"); So the html output will look like this, <input type="hidden" abc="123" /etc. I know...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.