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:
- <form id="myform" >
- <p class="comment">Name</p>
- <p><input type="text" name="name"></p>
- <p class="comment">Email</p>
- <p><input type="text" name="email" value="<? echo $_POST['email']; ?>" size="50"></p>
- <p><input type="button" onClick="dosubmit()" value="Submit"></p>
- </form>
- <div id="result" style="padding:5px;"></div>
- <script>
- function dosubmit( ) {
- new Ajax.Request('includes/add.php', { method: 'post',
- parameters: $('myform').serialize() } );
- $('myform').reset();
- }
- </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.