0

So I am trying to have the user confirm their action before they submit the form, so I tried using the confirm box. When I tested it, even when I pressed Cancel in the confirm box the form submitted. So I tried just setting variable 'c' to false and then saying if c==true, submit the form, and the form still submitted! I don't understand why this is happening. Any help would be appreciated!

So just to be clear, the form still submits in the following code:

<button onclick=\"extendBids('$studentID')\">Extend Bid</button>
    <input type=\"radio\" name=\"extendBid\" id=\"$studentID 2\" value=\"$studentID\" style=\"visibility: hidden\"></input>


function extendBids(studentID) {
   document.getElementById(studentID+" 2").checked=true;
   //var c=confirm("Are you sure? This action cannot be undone.");
    var c=false;
    if (c==true){
      document.forms["addToRush"].submit();
   }
}

1 Answers1

0

Try this -

<button onclick=\"extendBids('$studentID');\">Extend Bid</button>
    <input type=\"radio\" name=\"extendBid\" id=\"$studentID 2\" value=\"$studentID\" style=\"visibility: hidden\"></input>


function extendBids(studentID) {
   document.getElementById(studentID+" 2").checked=true;
   if(confirm("Are you sure? This action cannot be undone.")){
      document.forms["addToRush"].submit();
      return true;
   }
   return false;
}
brainless coder
  • 6,310
  • 1
  • 20
  • 36