Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    Aug 2004
    Location
    UK
    Posts
    56
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Form Submission Confirmation

    Right, my javascript knowledge is very limited but I'm pretty sure what I'm trying to do is possible.

    I have a form and when it is submitted I want an alert box to come up for the user so they can confirm the submission of the form.

    If they click OK, I want the form to carry on as if they had just submitted the form normally, and if they click Cancel I want the form to not be submitted and for the user to stay where they are.

    Sounds simple enough and I've searched for something that does this but none of the scripts I found do exactly this, so how do I do it?

    Many thanks in advance.

  • #2
    Senior Coder
    Join Date
    Feb 2004
    Location
    Edinburgh
    Posts
    1,352
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Sicton
    I've searched for something that does this but none of the scripts I found do exactly this
    what have you got so far?
    *keep it simple (TM)

  • #3
    New Coder
    Join Date
    Aug 2004
    Location
    UK
    Posts
    56
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Something along the lines of...

    Code:
    function confirm_delete(){
            var agree=confirm("Are you sure you wish to delete the selected comment(s)?");
            if (agree){
            // ???
            }

  • #4
    Senior Coder
    Join Date
    Feb 2004
    Location
    Edinburgh
    Posts
    1,352
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Sicton
    Code:
    function confirm_delete(){
            var agree=confirm("Are you sure you wish to delete the selected comment(s)?");
            if (agree){
            // ???
            }

    Code:
    function confirm_delete()
    {
            if (confirm("Are you sure you wish to delete the selected comment(s)?")) return true;
            else return false;
    }
    *keep it simple (TM)

  • #5
    Regular Coder
    Join Date
    Nov 2003
    Location
    Vancouver Island Canada
    Posts
    139
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    <script language="JavaScript">
    function chkForm() {
        return confirm("Are you sure you want to send form?");
    }
    
    </script>
    ...    
    <FORM action = "test.htm" onsubmit = "return chkForm();" >
        <input id="ID00" type="text" value="00"> <br />
        <input type="submit" />
    </FORM>
    even simpler
    Code:
    <FORM action = "test.htm" onsubmit = "return confirm('Are you sure you want to send form?');" >
        <input id="ID00" type="text" value="00"> <br />
        <input type="submit" />
    </FORM>
    Last edited by glenmac; 04-20-2005 at 04:54 PM.

  • #6
    New Coder
    Join Date
    Aug 2004
    Location
    UK
    Posts
    56
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Cheers, I didn't know it was so simple as that second option you offered - it works just perfectly.

    Thanks very much

  • #7
    Senior Coder
    Join Date
    Feb 2004
    Location
    Edinburgh
    Posts
    1,352
    Thanks
    0
    Thanked 0 Times in 0 Posts
    the second option might seem simpler but it's not as extensible, meaning you couldn't reuse the same code without re-copying it everytime you wanted to use that exact same message.
    *keep it simple (TM)

  • #8
    New Coder
    Join Date
    Aug 2004
    Location
    UK
    Posts
    56
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yeah, hence the benefit of using functions for portability.

    In this instance I'm only using it the once but valid point worth making.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •