On clicking the button, a message is supposed to be displayed in an alert box if all or any one text field is left empty. But nothing happens. Please debug this code. <html> <head> <title>More Than One Form</Title> <script> <body> function checkInput() { var isok = true; var count = document.forms[0].elements.length; var i = 0; for (i=0; i < count; i++) { if (documents.forms[0].elements.value == "") isOk = false; } if (isok == false) alert("Please Fill In All Responses"); } </script> </head> <body> <h1>Check It Out</h1> <form> Your Full Name: <input type="text" name="yname"><br><br> Email Address: <input type="text" name="email"><br><br> Postal Address: <input type="text" name="address"><br> </form> <hr><br> The second form begins here <hr> <form> <input type="button" name="doIt" value="check values" onClick="checkInput()"> </form> </body> </html>
A few issues: 1) You have an extra <body> tag inside the <script> tag. 2) You have a typo on this line: if (documents.forms[0].elements.value == "") ... it should be "document.forms[0]..." ("document" is singular) 3) You have a typo on this line: if (isok == false) ... it should be "if (isOk == false)" ... you are declaring a new variable, rather than updating the isOk variable. Remember that JS is case sensitive. Hope this helps! Regds drknght Check out the corrected code:
Thanks. That really worked. By the way what silly mistakes that were by me!!!! That's really too dumb of me.... :-(