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 4 of 4
  1. #1
    New Coder
    Join Date
    Jan 2013
    Posts
    74
    Thanks
    19
    Thanked 1 Time in 1 Post

    Need an action confirmed on a button press

    I have a form button which deletes members and I need a little popup to confirm that the person pressing the button really wants to delete the member. Once confirmed, I just need it to go ahead and proceed with the form processing like it normally would.

    How can I do this with a form button like this:

    Code:
    <input type="submit" name="Delete" value="Delete" />

    Thanks in advance for any help you can provide.

  • #2
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    A couple of different ways. You can keep the input type submit and give the form an onsubmit event that will raise the confirm box, returning false if the user changes his/her mind. Or change the input type submit to an input type button and put the onclick event to call a function that will use JavaScript to submit the form if the user goes ahead and confirms the delete, or does nothing if the user changes his/her mind.

    Just be sure to give the form an ID that is unique (all IDs must be unique) and use the DOM to reference it.
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

  • #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,043
    Thanks
    0
    Thanked 251 Times in 247 Posts
    Code:
    <input type="submit" name="Delete" value="Delete" onclick="return confirm('Do you want to continue?')" />
    Or:
    Code:
    <form ... onsubmit="return confirm('Do you want to continue?')">
    Of course, it is good programming practice to attach the event handlers in the js. I just showed you here an idea on how to solve this.

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,438
    Thanks
    75
    Thanked 4,372 Times in 4,337 Posts
    One comment: If you use WolfShade's suggestion to use <input type="button"> and then use JavaScript to do the actual submit of the form, it means that the form will no longer work, at all, for anybody who disables javascript. You have to decide if that is important to you.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

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