[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 250
  • Last Modified:

Why Stack Overflow with Confirm Box

I got stack overflow error when I implement a confirm box.  I don't know how to fix it.  Here is my code:

function confirm() {
  if(confirm('Are you sure to continue?')){
    document.forms[0].submit();
  }
  else{
    return false;
  }
}

<form name="form1" method="Post" action="create_inspection.jsp" onsubmit="return validate()">

<input type="Button" name="Submit" value="Enter Inspection" onClick="confirm()">
</form>

This form and javascript is in jsp create_inspection.jsp.  If user confirm the action, the request will be sent to the same page for database insert; otherwise, user stay with the page without submitting the form.

If I get rid of the confirm, everything is good. But if I add the confirm box, I got the stack overflow error.

0
qding
Asked:
qding
  • 2
  • 2
1 Solution
 
NetGrooveCommented:
You did overwritten the confirm() method with your function.
Cahnge it to this:

function doConfirm() {
  if(confirm('Are you sure to continue?')){
   document.forms[0].submit();
 }
 else{
   return false;
 }
}

<form name="form1" method="Post" action="create_inspection.jsp" onsubmit="return validate()">

<input type="Button" name="Submit" value="Enter Inspection" onClick="doConfirm()">
</form>


0
 
kingsfan76Commented:
try changing the your function name to something else other than confirm(), such as
function submitConfirm()
{......}
0
 
kingsfan76Commented:
almost posted at exact same time   :-)
0
 
NetGrooveCommented:
Hello qding,

do you confirm that upper comments solved your problem?
Or do you have also work overflow :)
0
 
jaysolomonCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Accept: NetGroove {http:#9814241}

Please leave any comments here within the next four days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jAy
EE Cleanup Volunteer
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now