jkkenzie Posted July 30, 2008 Share Posted July 30, 2008 Is it possible to put all fields(input boxes names) in an array and use on statement to find if they are empty/null then inform the user which input box/field is empty? Thanks in advance. regards, Jose Quote Link to comment Share on other sites More sharing options...
lemmin Posted July 31, 2008 Share Posted July 31, 2008 This will check all text inputs, but not things like radio buttons because those have default values. <html> <head> <script language="JScript"> function validate() { var inputs = frm1.getElementsByTagName("input"); var errString = ""; for (i=0; i<inputs.length && inputs[i].type != "submit";i++) { if (!inputs[i].value) errString += inputs[i].id+" must not be empty!\n"; } if (errString) alert(errString); } </script> </head> <bodY> <form id="frm1"> <input type="text" id="t1"><br> <input type="text" id="t2"><br> <input type="text" id="t3"><br> <input type="text" id="t4"><br> <input type="submit" onclick="validate()"> </form> </body> </html> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.