View Full Version : input name in javascript
houssam_ballout
12-12-2006, 05:18 AM
Hi
I want to create a javascript function in which:
when the user double clicks on some input form (like a text box), that function will return the name of that field?
thanks
coothead
12-12-2006, 07:13 AM
Hi there houssam_ballout,
does this example help...
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
window.onload=function(){
els=document.forms[0].getElementsByTagName('*');
for(c=0;c<els.length;c++) {
if(els[c].id!='container'){
els[c].ondblclick=function(){
alert(this.name);
}
}
}
}
</script>
</head>
<body>
<form action="#">
<div id="container">
<input type="text" name="foo"/>
<input type="text" name="blah"/>
<textarea cols="10"rows="10" name="tata"></textarea>
</div>
</form>
</body>
</html>
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.