I have a javascript method for validating the inputs in form and then return the serialised form data if it has passed validation.
function getFormData(form)
{
if(validation failed)
{
alert("Invalid input");
return;
//stop execution;
}
return $(form).serialize();
}
I have another function calling the above function.
var data = getFormData();
The problem I face is, if validation failed, the code execution doesn't stop execution. How to stop execution after alert ? I tried return false;
and then having a if
check to see if it has returned false
, it works. But is there any other way to stop executing immediately after alert. Because, I need to call this function at multiple places.