0
How to count text boxes on Web page by using java script function..
4 Antworten
+ 5
The following code will help to get number of textbox in the page.
var inputs = document.getElementsByTagName('input');
var count = 0;
for(var cpt = 0; cpt < inputs.length; cpt++)
if (inputs[cpt].type == 'text')
count++;
alert(count);
+ 5
A more efficient way would be to do:
var count = document.querySelectorAll
( "input[type=text]" ).length;
https://www.w3schools.com/jsref/met_document_queryselectorall.asp
+ 2
Thanks to all
0
Visph's way is best, but what do you class as a textbox? Whatever element you mean, put it in the string argument above. If you mean multiple element types, do the whole lot twice and add the values.