Rocking
asked on
Best way to validate from fields before ajax submission
Hi,
I need to validate form and once the form is validated then the ajax should submit the form?
validate method -> true -> call ajax -> form submitted...
I need to validate form and once the form is validated then the ajax should submit the form?
validate method -> true -> call ajax -> form submitted...
ASKER
is it the best approach to create a plain java script method to do the validation and then check in the another function its return value and then call ajax to submit the form?
function validate(){
xxx
xxx
xxxx
return true/false
}
function SubmitFrm() {
var chkfrmValidation = validate();
//if the return value true go for ajax
{
$.ajax({
type : 'post',
url : 'testsubmit',
data : $('#registerform').seriali ze(),
async : false,
dataType : "text",
beforeSend : function() {
$.blockUI({ message: '<h1><img src="../img/loading.gif" /> Processing...</h1>'});
},
complete : function() {
$.unblockUI();
},
success : function(data) {
$.unblockUI();
alert(data);
},
error : function(data) {
// check status && error
}
});
}
function validate(){
xxx
xxx
xxxx
return true/false
}
function SubmitFrm() {
var chkfrmValidation = validate();
//if the return value true go for ajax
{
$.ajax({
type : 'post',
url : 'testsubmit',
data : $('#registerform').seriali
async : false,
dataType : "text",
beforeSend : function() {
$.blockUI({ message: '<h1><img src="../img/loading.gif" /> Processing...</h1>'});
},
complete : function() {
$.unblockUI();
},
success : function(data) {
$.unblockUI();
alert(data);
},
error : function(data) {
// check status && error
}
});
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
What if we call the validate function in beforeSend : function() {} ?
Why even start the ajaxing if not valid?
Why even start the ajaxing if not valid?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
using Query:
http://www.jquerybyexample.net/2013/01/client-side-validation-jquery.html
using JavaScript:
http://jquerytools.org/demos/validator/server-side.html