Advanced Search

Results 1 to 2 of 2

Thread: Which Button was clicked?

  1. #1
    Join Date
    Oct 2005
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Which Button was clicked?

    Hey all, first post and couldn't find any related questions...

    I have a form with an onsubmt="return validateForm()"...

    I have two buttons: A Modify and a Delete. I have a validateForm function. In my function, how can I tell which button was clicked.

    <form name="form1" action="<?= $PHP_SELF ?> method="POST" onsubmit="return validateForm()">

    ... form stuff ....
    <input type="submit" name="modify" value="modify">
    <input type="submit" name="delete" value="delete">

    What I want to do is, when the delete button is clicked, provide the user with a messagebox stating, "You are about to delete a record, do you want to procede?"

    if Yes is clicked, process the form.

    Any thoughts.

    Thanks,
    jdc

  2. #2
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by jdc
    What I want to do is, when the delete button is clicked, provide the user with a messagebox stating, "You are about to delete a record, do you want to procede?"

    if Yes is clicked, process the form.
    If the confirmation is important, then it should be done through a server-side mechanism, just like input validation. Alternatively, make the user perform two actions so it won't be accidental: selecting a check box then a button, for instance. The final option would be to make the action reversible; a list of 'Trash'.

    If you really must do this client-side, then the confirmation action must be added directly to the button as that's the only way to determine which was clicked.

    Code:
    function confirmDelete() {
      return confirm('Are you sure you want to delete this entry?');
    }
    HTML Code:
    <input name="modify" type="submit" value="Modify" onclick="return confirmDelete();">
    Mike

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
  •