Revalidating form data
Revalidating form data
Hello,
Please help as I'am stuck. I am trying to validate some form input fields (inside a particular div on the form) on submit and I have written a function (submit handler) for that.
-
jQuery("#new_profile").submit(function(){
var contactTypes = new Array( 'mobile', 'email', 'twitter', 'im' );
var oneProvidedSystem = false;
var oneProvidedPublic = false;
var oneProvidedEach = false;
jQuery(contactTypes).each(function(i){
contactType = "#contact_types_system_" + contactTypes[i];
if( jQuery.trim(jQuery(contactType).val()).length != 0 ){
oneProvidedSystem = true;
}
});
jQuery(contactTypes).each(function(i){
contactType = "#contact_types_public_" + contactTypes[i];
if( jQuery.trim(jQuery(contactType).val()).length != 0 ){
oneProvidedPublic = true;
}
});
var systemErrorMsg = "<label class='error'>Please provide atleast one way for the sytem to contact you</label>"
var publicerrorMsg = "<label class='error'>Please provide atleast one way for the public to contact you</label>"
if(oneProvidedSystem == false){
jQuery("div#system_contact_types")
.css("border", "1px solid red")
.append(systemErrorMsg);
} else {
jQuery("div#system_contact_types")
.css("border", none);
}
if(oneProvidedPublic == false){
jQuery("div#public_contact_types")
.css("border", "1px solid red")
.append(publicerrorMsg);
} else {
jQuery("div#public_contact_types")
.css("border", none);
}
alert((oneProvidedSystem && oneProvidedPublic).toString());
if((oneProvidedSystem == true) && (oneProvidedPublic == true)){
oneProvidedEach = true;
} else {
oneProvidedEach = false;
}
return oneProvidedEach;
});
This works the first time. But when I edit and resubmit I dont think this function is called. Am I missing something here. Trying to get around this for quite a while now. Please help.