I'm getting the following error with the following JavaScript code:
RangeError: Maximum call stack size exceeded
I'm assuming that this means that I accidentally coded an infinite loop into my JavaScript. This code is from an ASP.NET MVC application that uses jQuery Validate. The purpose of this code is to check for images captured on the page prior to submission.
Essentially, this is another piece of front-end validation that needs to occur alongside jQuery Validate. It seems as though my only option is to run this code on submitting the form, especially since no other events happen between the "submit" button click and submission. Here is the code:
$('form').submit(function (e) {
e.preventDefault();
//If Corporation is selected as business type
if ($('#businessStructure').val() == "Corporation") {
//Checks CEO signature present
if ($("#signImage").length == 0 || $("#signImage").attr("src") == "") {
alert("Please sign and save your signature in the CEO signature pad");
$("#ceoError").show();
}
else {
//all good, an image exists
$('form').submit();
}
}
//If Sole Proprietor is selected as business type
else if ($('#businessStructure').val() == "SoleProprietor") {
//Checks CEO signature present
if ($("#signImage").length == 0 || $("#signImage").attr("src") == "") {
alert("Please sign and save your signature in the CEO signature pad");
$("#ceoError").show();
}
//Checks partner1 signature present
if ($("#signImage1").length == 0 || $("#signImage1").attr("src") == "") {
alert("Please sign and save your signature in the first partner signature pad");
$("#partner1Error").show();
}
else {
//all good, an image exists
$('form').submit();
}
}
else {
//Checks CEO signature present
if ($("#signImage").length == 0 || $("#signImage").attr("src") == "") {
alert("Please sign and save your signature in the CEO signature pad");
$("#ceoError").show();
}
//Checks partner1 signature present
if ($("#signImage1").length == 0 || $("#signImage1").attr("src") == "") {
alert("Please sign and save your signature in the first partner signature pad");
$("#partner1Error").show();
}
//Checks partner2 signature present
if ($("#signImage2").length == 0 || $("#signImage2").attr("src") == "") {
alert("Please sign and save your signature in the second partner signature pad");
$("#partner2Error").show();
}
else {
//all good, an image exists
$('form').submit();
}
}
});
This is the first time I have done a concurrent event with a MVC app form submission. Is there a different approach I am unaware of?