jonnypixel
jonnypixel

Reputation: 327

Uncheck check box some other action

I know it may look wierd but everything works fine except the bit where iam tryin to grab the id and attach it to the [name=checkme]

How do i go about formatting that line so that the id will be recoginsed.

$('input:checkbox[name=checkme'+id+']').attr('checked',"");  

It wont work as is but if i remove the +id it works and unchecks all checkboxes.

Hope that makes sense :)

Here is my code:

    <script type="text/javascript">    

    function deleterow(id) {

    var txt = $.ajax({

    (do stuff here)     

    }).success


    $('input:checkbox[name=checkme'+id+']').attr('checked',"");  

    }

    </script>

Upvotes: 0

Views: 148

Answers (2)

nnnnnn
nnnnnn

Reputation: 150080

If you are trying to select an element that has a name attribute like checkme1 where the 1 is in the variable id then what you already have should work:

$('input:checkbox[name="checkme'+id+'"]').attr('checked',"");

If you are trying to select an element with an id attribute that is in your id variable then this should work:

$('#' + id).attr('checked',"");

If that doesn't work please post the html for the checkbox(es) in question so that I can see what you're talking about.

Note that to uncheck a checkbox you should say .prop("checked", false); rather than using attr() (unless you are on a version of jQuery before 1.6).

Upvotes: 1

pete
pete

Reputation: 25091

$('input:checkbox[name="checkme' + id + '"]').attr('checked', false);

Upvotes: 1

Related Questions