2

Here I don't want to pass argument from submit buttons. Could anyone help me in prompting a confirm message accordingly

return confirm("Are you sure to Approve/Reject/Delete ?");

my html code

<form name="pendingrequest" id="pendingrequest" action="formhandler.php" method="POST" onsubmit="return confirmation(this);">
            <table >
                <tr>
                    <td><input type="submit" name="action" value="Approve"></td>
                    <td><input type="submit" name="action" value="Reject"></td>
                    <td><input type="submit" name="action" value="Delete"></td>
                </tr>
            </table> 
</form>

For example, if somebody click on approve, I want this :

return confirm("Are you sure to Approve?");
Asenar
  • 6,732
  • 3
  • 36
  • 49
JakeNsmith
  • 45
  • 6
  • try http://stackoverflow.com/questions/9091001/how-to-show-confirmation-alert-with-three-buttons-yes-no-and-cancel-as-it – Vinod VT Nov 01 '13 at 10:28
  • @VinodVT: The question is, in my form I have 3 submit buttons. I need to prompt message like Do you wish to approve when I submit Approve button, and "Do u wish to reject when I submit reject button" and so on. – JakeNsmith Nov 01 '13 at 10:30

1 Answers1

1

There is no cross-browser solution if you use onsubmit

The only way to do this is to bind event to buttons instead of submit form:

<!DOCTYPE html>
<html>
 <head>
  <script>
   function init()
   {
    document.getElementById("pendingrequest").onsubmit = function(e)
    {
     console.log(e.target.value);
     console.info(e.srcElement);
     return false;
    }

    var submits = document.getElementsByClassName("submit-test");
    for(var i=0;i<submits.length;i++)
    {
     submits[i].onclick = function(e){
      var value = this.value;
      return confirm("Are you sure to "+value+" ?");
     }
    }
   }
  </script>
 </head>
 <body onload="init()">

  <form name="pendingrequest" id="pendingrequest" action="" method="POST" >
   <table >
    <tr>
     <td><input class="submit-test" type="submit" name="action" value="Reject"></td>
     <td><input class="submit-test" type="submit" name="action" value="Approve"></td>
     <td><input class="submit-test" type="submit" name="action" value="Delete"></td>
    </tr>
   </table> 
  </form>
 </body>
</html>
Asenar
  • 6,732
  • 3
  • 36
  • 49