Web Analytics Made Easy -
StatCounter Confirmation box - When pressing cancel, I want it to stop the form being sent - CodingForum

Announcement

Collapse
No announcement yet.

Confirmation box - When pressing cancel, I want it to stop the form being sent

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Confirmation box - When pressing cancel, I want it to stop the form being sent

    I am the webmaster of a website called SodaHertz and I am developing the administrator's controls at the moment. Below each news post is a button that says 'Delete this article' and the owners of SodaHertz want me to make it so a Javascript confirmation box is used to ask them 'Are you sure you want to delete this article'. If they press 'No' or 'Cancel' then the form should not be submitted however I am not sure how to do this. I found this script on Google which I can understand, I just need to know how to stop forms being submitted.

    Code:
    <script language="JavaScript">
    <!--
    function confirm_entry()
    {
    input_box=confirm("Click OK or Cancel to Continue");
    if (input_box==true)
    
    { 
    // Output when OK is clicked
    // The form should be submitted
    }
    
    else
    {
    // Output when Cancel is clicked
    // The form should not be sent
    }
    
    }
    -->
    </script>
    
    <form onSubmit="confirm_entry()" method="POST" action="adminprocess.php">
    <input type="submit" >
    </form>
    The information is being sent to a PHP script called 'adminprocess.php'.
    Any help is apprectaied and I understand that this is probably a simple question to answer.
    Thanks,
    - Sam
    RomNet - DS Flashcart Reviews

  • #2
    Just do this
    Code:
    <form action="adminprocess.php" method="post" onsubmit="return confirm('Click OK or Cancel to Continue');">
    <input type="submit" value="Submit">
    </form>
    Return the result of confirm. If OK is press it returns true allowing the form to submit, if cancel is clicked or it is closed it returns false so the form is not submitted.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

    Comment


    • #3
      Thanks a lot!
      (Also I nominated you for Helpful Member Award)

      - Sam
      RomNet - DS Flashcart Reviews

      Comment


      • #4
        You're welcome and thank you.
        ||||If you are getting paid to do a job, don't ask for help on it!||||

        Comment

        Working...
        X