SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member aaron_karp's Avatar
    Join Date
    Jun 2003
    Location
    Boston
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Simple Comfirm Button on Submit

    I have two submission buttons on my form, and I need to make some javascript that will pop up a confirmation (Are you sure you want to submit?) when only one of the two has been pushed.

    I'm quite inexperienced with javascript, so I'm not really sure how to do this. I've tried using onSubmit in the <form> tag but that pops up a message for both buttons.

    Any suggestions? Thanks.

  2. #2
    SitePoint Member
    Join Date
    Mar 2004
    Location
    USA
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You are getting the confirmation message because you made both the buttons of type submit. If you want to keep both buttons as submit you will have to write separate javascript functions for each of the buttons.
    For the button on which you need the confirmation message create the a javascript like
    function clickButton1(){
    confirm ("Do u want to do this?");
    document.form.submit();
    }

    for the onclick event handler of the other button

    function clickButton2(){
    document.form.submit();
    }

    hope this helps.

  3. #3
    SitePoint Member aaron_karp's Avatar
    Join Date
    Jun 2003
    Location
    Boston
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That helps enormously. Thanks.

  4. #4
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you want to keep both buttons as submit you will have to write separate javascript functions for each of the buttons.
    Code:
    <html>
    <head>
    <title>untitled</title>
    </head>
    <body>
    <form action="javascript&#58;alert('submitted')">
    <input type="text" name="txt" />
    <input type="submit" value="confirm" onclick="return confirm('Submit this form?')" />
    <input type="submit" value="no confirm" />
    </form>
    </body>
    </html>
    ::: certified wild guess :::


Bookmarks

Posting Permissions

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