Your Ad Here

Simple Javascript Delete Confirmation

Put this in between the tags...

JavaScript:
  1. function confirmDelete(delUrl) {
  2. if (confirm("Are you sure you want to delete this item?")) {
  3. document.location = delUrl;
  4. }
  5. }


... and make your delete link look like this...

HTML:
  1. <a href="javascript:confirmDelete('?param1=1&item=4')">some link</a>

Enjoy.
Meshach

1 comment so far

  1. wesley August 9, 2007 6:45 am

    Or:

    pseudocode:
    confirmDelete(this);

    in confirmDelete:
    if are you sure
    go to this.href + '?delete=1' (or &delete=1 if there already is ? in the url)

    if users don't have js they will instead see a confirmation page (because there is no ?delete=1 in the orig url)

Leave a comment

Please be polite and on topic. Your e-mail will never be published.