2

I am unable to check the checkbox only if I click on the row but I want to click it in both ways. This is my method i am using:

$("table tr").click(function(){
    var id=$(this).attr("id");
            //This is because i dont want first row to be able to select
    if(typeof(id)!="undefined"){
        if($("#select-"+id).attr("checked")!="checked")
            $("#select-"+id).attr("checked","checked");
        else
            $("#select-"+id).removeAttr("checked");
    }
});

Also here you can live view it sabrio.eu5.org/admin.php username: admin password: admin

2 Answers 2

3

My best guess is that your TR click function is cancelling out the default behaviour of the checkbox being clicked. So when you click the checkbox it is like it is being clicked twice.

try adding a click event to you checkboxes like this...

$("[type='checkbox']").click(function(e) {
        e.stopPropagation();
});

you will need to change the selector to something that suits your html

See here for a working example

Sign up to request clarification or add additional context in comments.

Comments

1

Would this help

     $("table tr").click(function(){
      var checkbox = $(this).find(':checkbox');
      checkbox.attr('checked', !checkbox.attr('checked'));
     });    

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.