tags:

views:

126

answers:

5

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.

+1  A: 

Something like this maybe?

$('input:submit[name="Delete"][value="Delete"]')
Mickel
Yes, that's it! Thank you!
cf_PhillipSenn
+1  A: 

Your question is a bit vague, but if I interpret it correctly, you actually want to know the syntax to select a input type="submit" name="Delete" value="Delete" in jQuery?

If so, here it is:

$('input:submit[name="Delete"][value="Delete"]')
BalusC
A bit vague? My goodness I don't know how much more I could have put into the question without going on and on!
cf_PhillipSenn
The topic title did in no way cover the **actual** problem/question.
BalusC
+4  A: 

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.
    });

});
Jonathan Sampson
A: 

--> This is in asp.net code with c#.


//Front End
<asp:ImageButton ID="btnimgdelete" ImageUrl="~/Images/deleteGrid.gif" OnClientClick="return delete_in_grid()" runat="server" />

//Put this in <head> tag.
<script type="text/javascript" language="javascript">
function delete_in_grid()
    {
        var r=confirm("Are You sure, that your want to delete selected record?");
        if (r==true)
          {
          return true;
          }
        else
          {
          return false;
          }
    }
</script>

//Guide me if i am wrong.

Ashish
Thanks, but I don't know asp.net with c#. This is a jQuery question.
cf_PhillipSenn
+3  A: 
$(':submit[name="Delete"][value="Delete"]').click(function() {
    return window.confirm(this.title || 'Delete this record?');
});
David