Administrators Nathan Posted December 12, 2013 Administrators Share Posted December 12, 2013 I'm trying to check a rule that if false an alert box pops up on submit and gives a message. The user can then only select ok and fix the issue and the submit does not happen.The condition that needs to be met is if $totalqty > $qty then pop up the alert box with message they need to fix before they can submit.I've tried this: if($totalqty > $qty) { echo '<form method="post" action="#" onsubmit="return confirm('You\'ve selected too many items please remove some before continuing.');">'; } else { echo '<form method="post" action="#">'; } The above allows the user to hit ok or cancel, I don't want them to be able to continue until they fix the issue. So is there a way for the alert box to just have an OK button and it not submit? Quote Link to comment Share on other sites More sharing options...
Administrators Nathan Posted December 12, 2013 Author Administrators Share Posted December 12, 2013 One small piece I missed. alert('selected too many items'); return false; Quote Link to comment Share on other sites More sharing options...
Administrators Nathan Posted December 12, 2013 Author Administrators Share Posted December 12, 2013 While the above worked a better solution was the following. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Form Check</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <script type="text/javascript"> <!-- function check() { var nmbr = document.getElementById("number").value; if (nmbr > 5){ alert("the number is too high"); return false; } return true; } // --> </script> </head> <body> <h1>Form Check</h1> <form action="#" method="get" onsubmit="check();"> <input type="text" name="number" id="number" value=""><br> <input type="submit" name="submit" value="submit"> </form> </body> </html> Quote Link to comment 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.