SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Thread: Confirm Delete

  1. #1
    SitePoint Addict
    Join Date
    Jan 2008
    Location
    Shaw AFB
    Posts
    282
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Confirm Delete

    Seems pretty simple - yet the tutorials I've read are not practical (confirm 'are you having fun?')

    I have a form with select boxes.

    When you select one or more, you can click "remove".

    the form is set up like so:

    <form method="post" action="remove.php">

    remove.php processes the array that is posted to it and removes the appropriate entries.

    All I need is a javascript confirm/cancel box. Maybe I'm not googling the right thing.

    Also, should I be using
    <input type="button">

    or
    <input type="submit">
    ?
    ~ Nate L ~

  2. #2
    SitePoint Enthusiast claire0917's Avatar
    Join Date
    Jul 2009
    Posts
    44
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi Natel,

    you can do it like this:

    <input type="submit" value="Delete" onclick="return confirm('Are you sure you want to delete?');">

    confirm() function returns a true or false. If true, the submit action would proceed.
    Last edited by claire0917; Jul 27, 2009 at 18:14. Reason: typo

  3. #3
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,631
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hmm. That would work via the onsubmit event for the <form> tag; I've not seen that method used on the onclick event of a submit button.

    Code HTML4Strict:
    <form method="post" action="remove.php" onsubmit="return confirm('Are you sure you want to delete?');">
    Ian Anderson
    www.siteguru.co.uk

  4. #4
    SitePoint Addict
    Join Date
    Jan 2008
    Location
    Shaw AFB
    Posts
    282
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This form has two buttons: E-mail and Delete

    Now I'm running into a big big issue that makes no sense to me...


    HTML Code:
    <input type="submit" value="E-mail Files" id="emailbtn" name="emailbtn" />
    <input type="submit" value="Remove Files" onclick="confirmDelete()" id="removebtn" name="removebtn"/>
    in the <head> portion of my page, I have this function:

    Code:
    <script type="text/javascript">
    
    function confirmDelete() {
    	confirm("Remove these Files?");
    }
    
    </script>
    And if I hit CANCEL - it STILL submits the form onto the form action.
    ~ Nate L ~

  5. #5
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    You need to return false to stop it submitting:
    Code javascript:
    function confirmDelete() {
        return confirm("Remove these Files?");
    }
    Code html:
    <input type="submit" value="Remove Files" onclick="return confirmDelete()" id="removebtn" name="removebtn"/>
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  6. #6
    SitePoint Addict
    Join Date
    Jan 2008
    Location
    Shaw AFB
    Posts
    282
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ah! return in both spots... WORKS!!
    ~ Nate L ~

  7. #7
    SitePoint Member
    Join Date
    Jul 2009
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just what I was looking for
    I asked God if he made Eve out of Adam's rib, he didn't answer.


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
  •