]>
One excellent use of this method is to validly add attributes to form elements to be used in form validation.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd"
[
<!ATTLIST input custom1 CDATA #IMPLIED>
<!ATTLIST input extradata CDATA #IMPLIED>
]>
<html lang="en">
<head>
<title>Specifying Custom HTML Attributes</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="author" content="Roderick Divilbiss">
<meta name="copyright" content="© 2005-2010 Roderick Divilbiss">
<script type="text/javascript">
function showAtts(el) {
var out='Attributes for '+el.name+'\n';
out+='ID '+el.id+'\n';
out+='TYPE '+el.type+'\n';
out+='VALUE '+el.value+'\n';
out+='CUSTOM1 '+el.getAttribute('custom1')+'\n';
out+='EXTRADATA '+el.getAttribute('extradata')+'\n';
alert(out);
}
function setAtt(el1,el2) {
el1.setAttribute('extradata',el2.value);
showAtts(el1);
}
function toggleNote() {
var oEl=document.getElementById('noteLink');
if (oEl.innerHTML=='[more]') {
document.getElementById('note').style.display='block';
oEl.innerHTML='[hide]';
}else{
document.getElementById('note').style.display='none';
oEl.innerHTML='[more]';
}
}
</script>
<style type="text/css">
#topmenu {
top:10px;
z-index:2;
position:absolute;
width:96%;
color:#FFFFFF;
background-color:#B36B00;
font-size:80%;
text-align:right;
padding-right:15px;
height:16px;
voice-family: "\"}\"";
voice-family: inherit;
height:15px
}
html>body #topmenu {
height:15px;
}
</style>
</head>
<body>
<input type="text" id="t1" name="t1" size="20" value="This has custom attributes" custom1="Value of custom attribute one" extradata="extradata value"> <input type="button" value="Show Value of Custom Attributes" name="B1" onclick="showAtts(document.getElementById('t1'));"><br>
<input type="text" id="t2" name="t2" size="20"> <input type="button" onclick="setAtt(document.getElementById('t1'),document.getElementById('t2'));" value="Set New Value for custom1" name="b2"></div>
</body>
</html>
Date Validation Using JavaScript .
Cross-Browser Clipboard Copy .
Loading Images With Remote Scripting .
Why JavaScript In Hyperlinks Is Bad .
Change The Submit Button To Show Waiting For AJAX Response .
European Date Validation Using JavaScript .
Database Results To Client Side Array .
Reading Files With JavaScript .
AJAX For Plain Text And HTML .