sseeley Posted June 23, 2011 Share Posted June 23, 2011 Hello, can anyone help me with this Javascript? When I click cancel it still submits the form? function confirmSubmit() { var r=confirm("Please confirm you have updated the divisors correctly"); if (r==true) { submitOK = "true"; } else { submitOK = "false"; } if (submitOK == "false") { return false; } } Quote Link to comment https://forums.phpfreaks.com/topic/240198-straight-forward-java-script-not-working/ Share on other sites More sharing options...
KevinM1 Posted June 23, 2011 Share Posted June 23, 2011 Have you tried simplifying it like: function confirmSubmit() { var r = confirm("Please confirm you have updated the divisors correctly"); if(r != true) { return false; } return true; } Quote Link to comment https://forums.phpfreaks.com/topic/240198-straight-forward-java-script-not-working/#findComment-1233800 Share on other sites More sharing options...
sseeley Posted June 23, 2011 Author Share Posted June 23, 2011 Have tried this modification but the form still submits? Quote Link to comment https://forums.phpfreaks.com/topic/240198-straight-forward-java-script-not-working/#findComment-1233801 Share on other sites More sharing options...
KevinM1 Posted June 23, 2011 Share Posted June 23, 2011 How are you invoking your confirmSubmit function? Quote Link to comment https://forums.phpfreaks.com/topic/240198-straight-forward-java-script-not-working/#findComment-1233802 Share on other sites More sharing options...
sseeley Posted June 23, 2011 Author Share Posted June 23, 2011 <form action = 'addxxx.php' method = 'POST' name = 'addYearDivisor' onsubmit = 'confirmSubmit()'> Quote Link to comment https://forums.phpfreaks.com/topic/240198-straight-forward-java-script-not-working/#findComment-1233803 Share on other sites More sharing options...
KevinM1 Posted June 23, 2011 Share Posted June 23, 2011 The following works: <!doctype html> <html lang="en-us" dir="ltr"> <head> <meta charset="utf-8" /> <title>Form submission test</title> </head> <body> <form name="myForm" action="" method="post"> <input name="submit" type="submit" value="Submit" /> </form> </body> <script type="text/javascript"> var oForm = document.forms["myForm"]; oForm.onsubmit = function() { return confirm("Do you wish to continue?"); } </script> </html> Quote Link to comment https://forums.phpfreaks.com/topic/240198-straight-forward-java-script-not-working/#findComment-1233821 Share on other sites More sharing options...
sseeley Posted June 23, 2011 Author Share Posted June 23, 2011 Thanks for your help, this worked fine. Quote Link to comment https://forums.phpfreaks.com/topic/240198-straight-forward-java-script-not-working/#findComment-1233825 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.