I've created a form that is used to review a person on a website, however when the form is submitted nothing happens and console is showing a 'Maximum Call Stack Exceeded'. Hopefully someone can help point out the error in my code stopping this from working. Here is the form code:
<form id="fReviewMe" method="post" action="/process/review-p.cfm" enctype="multipart/form-data" style="display:none">
<label style="padding-top:10px"><i class="fa fa-asterisk magenta"></i> Your Name:</label>
<input type="text" name="uname" id="uname" class="span8" placeholder="Please tell us your name">
<label><i class="fa fa-asterisk magenta"></i> Your Business Name:</label>
<input type="text" name="business" id="business" class="span8" placeholder="Please tell us your business name">
<label><i class="fa fa-asterisk magenta"></i> Your Review:</label>
<textarea name="reviewmsg" id="reviewmsg" class="span8" rows="8" placeholder="Please add your review in here"></textarea>
<!--- form errors --->
<div id="dFormErrors" class="row" style="display:none;padding-bottom:20px;">
<span id="sEMessage" class="pull-right"></span>
<i class="fa fa-asterisk magenta pull-right"></i>
</div>
<!--- form buttons --->
<div id="dButtonsReviewForm" class="row">
<a onClick="checkForm()" name="submit" class="cta pull-right">Submit</a>
<a href="javascript:hideReviewMe()" class="pull-right cta" style="margin-right:6px">Cancel</a>
</div>
<!--- form saving --->
<div id="dSavingReviewForm" style="display:none">
<span class="pull-right hibuBtn" style="cursor:wait"><i class="fa fa-spinner fa-spin"></i> Saving</span>
</div>
Here is the JS code:
/* intercept submit event */
$( "#fReviewMe" ).submit(function(event) {
checkForm();
event.preventDefault();
});
/* form validation */
function checkForm(){
var errors = 0;
var cuname = $('#uname').val();
var ccompany = $('#business').val()
var creview = $('#reviewmsg').val()
var cstars = $('#rStar').val()
var eMessage = "";
$('#dFormErrors').hide();
$('input').removeClass('validFalse');
$('textarea').removeClass('validFalse');
if ($('#tnc').is(':checked')) {
}
else{
eMessage = "Please tick to accepts out terms and conditions";
errors++;
}
if(cstars.length < 1){
$("input").blur();
$("textarea").blur();
eMessage = "Please choose a star rating";
errors++;
}
if(creview.length < 1){
$('#reviewmsg').focus();
$('#reviewmsg').addClass('validFalse');
eMessage = "Please add your review";
errors++;
}
else{
$('#reviewmsg').addClass('validTrue');
}
if(ccompany.length < 1){
$('#business').focus();
$('#business').addClass('validFalse');
eMessage = "Please tell us your business name";
errors++;
}
else{
$('#business').addClass('validTrue');
}
if(cuname.length < 1){
$('#uname').focus();
$('#uname').addClass('validFalse');
eMessage = "Please tell us your name";
errors++;
}
else{
$('#uname').addClass('validTrue');
}
/* check errors and submit */
if(errors > 0){
$('#dFormErrors').slideDown();
$('#sEMessage').html(eMessage)
}
else{
$('#dButtonsReviewForm').hide();
$('#dSavingReviewForm').show();
$('#fReviewMe').submit();
}
}
Thanks in advance
The call stack is limited in size, and when it's exceeded, the RangeError is thrown. This can happen when a deeply nested function is called, or when a lot of new variables are created. The most common way to fix this error is to reduce the number of function calls, or to limit the number of variables that are created.
The JavaScript RangeError: Maximum call stack size exceeded is an error that occurs when there are too many function calls, or if a function is missing a base case.
The "RangeError: Maximum call stack size exceeded" error occurs when a function is called so many times that the invocations exceed the call stack limit. To solve the error, specify a base case that has to be met to exit the recursion.
Introduction. If you see the “Maximum Call Stack Size Exceeded” error, there's likely a problem with a recursive function within your JavaScript code. More specifically, the issue lies with the function calling on itself indefinitely.
Replace $('#fReviewMe').submit();
with:
$('#fReviewMe')[0].submit();
calling DOM node method submit
to avoid submit jQuery handler 'loop'.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With