Question

I have this code currently:

<form id="form1" name="form1" method="post" action="" 
       onclick="return confirm('This is irreversible. Are you sure?');">
   <input type="hidden" name="act" value="run">
   <input id="btnDelete" name="btnDelete" type="button" value="Delete Selected"/>
</form>

<?php
    if (isset($_POST['act']))
    {
        echo "<script>alert(\"sup\");</script>";
    }
?>

The alert is to check if it will run when i press "ok". It currently does not. I'm at my wits end, especially since I'm pretty much a noob at Javascript. If anyone can help it'll be greatly appreciated!

Was it helpful?

Solution

Give a type="submit" to your submit button, and a onsubmit event to your form:

<form id="form1" name="form1" method="post" action="" 
   onsubmit="return confirm('This is irreversible. Are you sure?');">
  <input type="hidden" name="act" value="run">
  <input id="btnDelete" name="btnDelete" type="submit" value="Delete selected"/>
</form>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top