0

I have an HTML in which I have table, one column of table contains checkboxes and other contains text.

One checkbox is coming auto punched from the backend when the page loads. I want to make that checkbox readonly. below is the code I am using but its not working. pls suggest.

$(document).ready(function(){
  $('tr td').each(function(){
    $('this').find('input[type="checkbox"]:checked').prop('readOnly',true);
  });
});
Vaibhav
  • 105
  • 1
  • 8

4 Answers4

0

Change this

$('this').find('input[type="checkbox"]:checked').prop('readOnly',true);

to this

$(this).find('input[type="checkbox"]:checked').attr('disabled','disabled'); 
Kartikeya Khosla
  • 18,743
  • 8
  • 43
  • 69
0

Besides using a string for 'this' and the weird camel-casing (which doesn't really matter, both because the HTML isn't case-sensitive and also because jQuery fixes it to lowercase anyway) there's the simple fact that there's no such thing as a readonly checkbox. See for yourself (if you're interested why - simply put, READONLY prevents changing the field's value - and when clicking on a checkbox you're actually changing its state)

Instead, use disabled:

$(this).find('input[type="checkbox"]:checked').prop('disabled',true);
Community
  • 1
  • 1
yuvi
  • 18,155
  • 8
  • 56
  • 93
0

return false on click event...

Try this:

$('tr td').each(function(){
    $(this).find('input[type="checkbox"]:checked').on('click', function(){ return false });
});

::JsFiddle::

mk117
  • 753
  • 2
  • 13
  • 26
0

You can use to disable all checkboxes

 $('input[type="checkbox"]:checked').prop('disabled', "true");  
Gemini
  • 89
  • 1