I’m trying to make a universal “Check Empty” javascript function. What I figured I would do was onsubmit get the number of input boxes in the form and take it’s length like so:
I did pass the form name into the function via this.name and called it formVar
var len = formVar.input[].value;
Then I would use that variable as a limit to a loop so I could check each one and see if it was empty. What’s the problem with the above code snippet? Is there a way to get a number of inputs in a form?
DEMO
input[]isn’t a valid identifier in JavaScript, so you’ll need to access these inputs as a string index on your form: