Here’s another simple jQuery snippet I like to add to my projects. This will allow you to present a javascript confirm dialog when a user clicks on a link or a submit button with a confirm attribute it. The value of the confirm attribute will be the text displayed in the confirm dialog box. I often use this for delete button so the user has a chance to back out.

$(function() {
   $("a[confirm], input[type=submit][confirm]").click(function() {
       conf = confirm($(this).attr("confirm"));
       if(!conf)
           return false;
   });
}

« »