/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Add 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
[/CODE]

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>
[/CODE]

However this throws an error.
Is something like this possible?

thanks

to post a comment
HTML

2 Comments(s)

Copy linkTweet thisAlerts:
@nap0leonMay 22.2012 — Here's an example of using a custom attribute on a select box option.

http://www.jasondahlin.com/2011/coding-tips/selectBox-custom-values.asp

Basically, you use [i]selector[/i].getAttribute("special")
×

Success!

Help @gregd spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...