Monday, 15 August 2011

validation - How do I include an Ajax validator before sending -



validation - How do I include an Ajax validator before sending -

i managed create code submit form, works fine, can not implement validator not need it, shows no message not send form empty.

i searched not quite it. can help me?

<script type="text/javascript"> jquery(document).ready(function(){ jquery('#newsletter').submit(function(){ var dados = jquery( ).serialize(); jquery.ajax({ type: "post", url: "newsletter_cadastrar.asp?f=1", data: dados, success: function( info ) { $('#resultado-form-newsletter').html(data); } }); homecoming false; }); }); </script> <input id="nomenewslbase" name="nomenewslbase" type="text"> <input id="emailnewslbase" name="emailnewslbase" type="email">

thank attention.

if looking applying jquery validation rules can like:

<script type="text/javascript"> function validationrules() { } validationrules.prototype.initializesavevalidators = function() { jquery.validator.addmethod("csprojectname", function(value, element) { if ($.trim($('#txtprojectname').val()) == "") { if ($.trim($(element).val()) != '') homecoming true; else homecoming false; } else homecoming true; }, "project name required"); jquery.validator.addmethod("csdescription", function (value, element) { if ($.trim($('#txtdescription').val()) == "") { if ($.trim($(element).val()) != '') homecoming true; else homecoming false; } else homecoming true; }, "description required"); }; validationrules.prototype.enablesavevalidators = function () { jquery.validator.classrulesettings.csprojectname = { csprojectname: true }; jquery.validator.classrulesettings.csdescription = { csdescription: true }; }; validationrules.prototype.disablesavevalidators = function () { jquery.validator.classrulesettings.csprojectname = { csprojectname: false }; jquery.validator.classrulesettings.csdescription = { csdescription: false }; }; jquery(document).ready(function () { var validationrules = new validationrules(); validationrules.initializesavevalidators(); validationrules.enablesavevalidators(); $("#btnsubmit").click(function () { applyjqueryvalidation(); homecoming false; }); }); function applyjqueryvalidation() { var isvalid = $('#newsletter').valid(); //here can manually check validations if (isvalid==true) { alert("valid"); //here ajax phone call }else{ alert("invalid"); } } </script>

also, need include jquery.validate.js

here jsfiddle working example.

ajax validation

No comments:

Post a Comment