I have a form with a lot of text fields and hidden input fields. Now I am trying to count those input fields of type text, but I can't get it to work.
I am using the following code:
var subtagid = document.getElementById('subtags').getElementsByTagName('input').getAttribute("text").length;
var inputs = document.getElementById('subtags').getElementsByTagName('input').length;
for(var i=0; i<inputs.length; i++)
{
if(inputs[i].getAttribute(‘type’)==‘text’)
{
subtagid++;
}
}
Does anyone know how I can do this?
varthe first time..getAttribute("text")instead oftypebut even that won't work since you're chaining that to a method that returns a list. Additionally, you're retrieving thelengthoninputstoo soon, so you can't iterate overinputs[i]. Make it simple!document.querySelectorAll('input[type="text"]').length;(you can replacedocumentwith an ID selector if needed).