OnSubmit does work right in the Validation plugin in jQuery

Posted by novellino on Stack Overflow See other posts from Stack Overflow or by novellino
Published on 2010-04-20T14:20:38Z Indexed on 2010/04/20 14:23 UTC
Read the original article Hit count: 262

Filed under:
|
|
|

Hello,

I an quite new to jQuery and I have a problem while trying to create a form. I am using the Validation plugin for validate the email (one the form's field). When I click the Submit button I want to call my own function because I want to save the data in an XML file.

This is my button: (as I understood the plugin uses "submit" for understand the button)

<input type="submit" name="submit" class="submit" id="submit_btn" value="Send"/>

and here is the script for the validation:

 <script type="text/javascript">
  $(document).ready(function() {

        //this is my form
 $("#contactForm").validate();

 /*save the valid data in the xml*/
 $(".submit").click(function() { 

var email = $("input#email").val(); var subject = $("input#subject").val(); var message = $("textarea#message").val();

if (email == "" || !$("#contactForm").valid()) { return false; }

var dataString = 'email='+ email + '&subject=' + subject + '&message=' + message; //alert("DATA: " +dataString);

$.ajax({ type: "POST", url: "SaveData.jsp", data: dataString,
success: function(data){}
});

 return false;

}); });

In general it works ok but I have two basic problems. When I click the button in the beginning having all the form empty, I get no message for the field required. Also when the data are valid and I am doing the submit, the form does not become clear after the submit.

If I deleted this script code, these actions are working properly but I can not save the data!

Does anyone know what is wrong?

Thanks a lot!

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about AJAX