I have a link in a module:

/* Delete Customer Link */
$output = t('

='.l('Delete Customer','customer/view/detail/remove',array(),'id='.$customerid.'&return=customer/view/detail&cc='.$_REQUEST['cc'].'&passport='.$_REQUEST['passport']).'=

');

Now what I want to do is, before this link is clicked, I need a pop up to occur Confirm ("Are you sure you want to delete?")

I was unable to figure out how to add this javascript confirm to this Drupal link. Any idea? I would prefer coding that is availale rather than looking for a module that enables me to do this, but any how, let me know?

Thanks,
Waqar

Comments

drupalina’s picture

Have a look at this site: http://www.sugarloving.com
when you try to vote it will give you an AJAX popup to login or register.

I'm no JS expert, but maybe with Firebug or other similar tools you can see their inline JS.

If you find a solution, please post it here.

benshell’s picture

The best practice way to do this is to make the link work without JavaScript first, and then add JavaScript using jQuery that finds your link and attaches the popup confirm code to it. This way your site still works if JavaScript is unavailable.

Start by added a new class to all your "delete customer" links (assuming there's more than one). Then add a new .js file using drupal_add_js(). Then in that file do something like this:

if (Drupal.jsEnabled) {
  $(document).ready(function() {
    // Find all the delete customer links
    var links = $("a.customerlink").click(function() {
      var r=confirm("Are you sure you want to delete?");
      if (r==true) {
        document.write("You pressed OK!");
      } else {
        document.write("You pressed Cancel!");
      }
    });
  });
}

Hopefully that will get you started. Note that I haven't tested this code.

- Ben -