Retrieve name of Form components

[Total: 0    Average: 0/5]

This example shows how to have javascript detect the name of the elements in a form.

Body Code:

<form name=exf1>
<input type=text name=t1 value="i am t1">
<input type=hidden name=h1 value="i am h1">
<input type=button name=b1 value="i am b1">
</form>
<a href="javascript:doIt()">show form's names</a><BR>
<script>
function doIt() {
var _s="";
for(var i=0;i<document.exf1.elements.length;i++)
_s+=document.exf1.elements[i].name+" * ";
alert(_s);
}
</script>

Times Viewed: 0

Leave a Reply

Your email address will not be published. Required fields are marked *