Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

count tags in form in JS function

Status
Not open for further replies.

mbwmbk

Programmer
Dec 12, 2002
19
0
0
US
Is there a way to count how many input tags in a form in a javascript function?
 
if you mean how many elements of tagname "input", then:
[tt]
<script language=&quot;javascript&quot;>
function countInputs() {
var e = document.formName.elements;
var iNumInputs = 0;
for (x = 0; x < e.length; x++) {
if (e[x].tagName.toLowerCase() == &quot;input&quot;) ++iNumInputs;
}
alert(iNumInputs + &quot; total inputs.&quot;);
}
</script>
[/tt]


total number of form elements is [tt]
document.formName.elements.length;[/tt]
=========================================================
if (!succeed) try();
-jeff
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top