0

How to count text boxes on Web page by using java script function..

19th Jul 2017, 2:54 AM
Amit
Amit - avatar
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);
19th Jul 2017, 3:01 AM
Silambarasan T
Silambarasan T - avatar
+ 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
19th Jul 2017, 6:07 AM
visph
visph - avatar
+ 2
Thanks to all
20th Jul 2017, 2:16 AM
Amit
Amit - avatar
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.
19th Jul 2017, 6:11 AM
James
James - avatar