<form action="form_processor.php" method="post" 
    onSubmit="return validateForm(this);">
<input type="text" name="first_name">
<input type="text" name="last_name">
<input type="submit" value="Submit">
</form>

<script language="JavaScript">
function validateForm(myform) {
 if (myform.first_name.value=="") {
    myform.first_name.focus();
    //We return false here so when onSubmit fails,
    //the form does not get submitted to "form_processor.php"
    return false;
  }
  if (myform.last_name.value=="") {
    myform.last_name.focus();
    return false;
  }
  //If we have reached this point, all elements checked out
  return true;
}
</script>