If the field is empty it should make an alert message saying you need to fill in your first name. Else it should submit the form. The alert message works but even if you do put something into the text input the form won't submit?
Any help would be great.
HTML Code:<?php require "database.php"; if (isset($_POST['submit'])) { echo "hello"; } else { ?> <html> <head> <script type="text/javascript"> function validateForm() { var x=document.forms["myForm"]["fname"].value; if (x==null || x=="") { alert("First name must be filled out"); return false; } } </script> </head> <body> <form name="myForm" action="<?php echo $_SERVER['PHP_SELF']?>" onsubmit="return validateForm()" method="post"> First name: <input type="text" name="fname"> <input type="submit" value="Submit"> </form> </body> </html> <?php } ?>



Reply With Quote


Bookmarks