Ok right, so I basically have a comment box and want users to post comments on certain pages. I just want a javascript function to alert the user if the comment field is empty. I have looked through the net, but for some reason I can't seem to get this simple code to work. I have tried getElementByID, have also called the forms explicitly but yet no luck. Can someone please point out what I'm doing wrong.
this is the sample html
And this is the simple javascript fileCode:<html> <head> <script type="text/Javascript" language ="Javascript" src="comments.js"></script> <title> About Us </title> </head> <body> <fieldset> <legend> Post Comment </legend> <form name="comments" action="../dbconnect/post_comments.php" onSubmit="return checkFields()" method="post"> <input type="text" name="comment" size="100" class="txt"/> <input type="hidden" name="source" value="aboutus" /> <input type="hidden" name="url" value="AboutUs.php" /> <input type="submit" class="btn2" value="Post" /> </form> </fieldset> </body>
Any help whatsoever will be greatly appreciated.Code:function checkFields() { missinginfo=""; var form = document.forms[0].elements[0]; if (form.value == "") { missinginfo += "\n - Comment"; } msg = "The following fields must be filled in\n"; if(missinginfo !="") { missinginfo = msg+ missinginfo + "\n"; alert(missinginfo); return false; } else return true; }


LinkBack URL
About LinkBacks
Reply With Quote
