I just wrote a confirm delete function that requires a class name:
jQuery(document).ready(function($) {
$('.ConfirmDelete').click(function() {
var question = $(this).attr('title');
if (question == '') question = 'Delete this record?';
return confirm(question);
});
});
Usage:
<input name="Delete" type="submit" value="Delete" class="ConfirmDelete" title="Delete #UsrName#?" />
I'd like to change the selector from .ConfirmDelete to something like:
$('input:submit').attr('name','Delete').val('Delete')
Meaning: If a submit button has the name 'Delete' and it's value is 'Delete', then go ahead and assume they want to confirm the delete without requiring them to have a ConfirmDelete class.
$(':submit[name="Delete"][value="Delete"]').click(function() {
return window.confirm(this.title || 'Delete this record?');
});
The following would apply to all present, and future instances of any submit button having both the name and value of "Delete":
$(function(){
$(":submit[name='Delete'][value='Delete']").live("click", function(e){
e.preventDefault(); // remove if not necessary
// Seriously, delete it.
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With