Simple Javascript Form Validation Tutorial
First, add onsubmit="return checkform(this);" to the <form> tag so it looks like the snippit below.
<form method="post" action="formmail.php" onsubmit="return checkform(this);">
Second, place this javascript within the <head> of your document. Voila - your done!
<script type="text/javascript"> <!-- function checkform ( form ) { // ** START ** if (form.name.value == "") { alert( "Please enter your name." ); form.name.focus(); return false ; } if (form.email.value == "") { alert( "Please enter your email address." ); form.email.focus(); return false ; } if (form.subject.value == "") { alert( "Please enter the subject." ); form.subject.focus(); return false ; } if (form.comments.value == "") { alert( "Please enter your comments." ); form.comments.focus(); return false ; } // ** END ** return true ; } //--> </script>