HTML Form Submit

HTML Form Submit

Hi,

I#'m new to Jquery and so i'm not even sure if this is even possible:

I want to run a php script when an html form is submitted. The PHP will run a check. If true it will submit the form as usual, if false it will call a javascript alert.

This what I have so far:

  1. <form id="myform" >
  2.  <p class="comment">Name</p>
  3.  <p><input type="text" name="name"></p>
  4.  <p class="comment">Email</p>
  5.  <p><input type="text" name="email" value="<? echo $_POST['email']; ?>" size="50"></p>
  6.  <p><input type="button" onClick="dosubmit()" value="Submit"></p>
  7. </form>

  8. <div id="result" style="padding:5px;"></div>

  9. <script>
  10. function dosubmit( ) {
  11.   new Ajax.Request('includes/add.php', { method: 'post',
  12.     parameters: $('myform').serialize() } );
  13.   $('myform').reset();
  14. }
  15. </script>
My add.php contains a simple if/else statement. When it evaluates as false I have the javascript alert code but tthe alert does not appear. Instead I have echoed some text text and that appears in the 'result' div below my form.

Is it possible to have the alert appear and also how would I submit the form if true?

Thanks in advance,

Johnny.