-1

AOA, I need to check checkbox by jquery on values basis. e.g now I want when this page is loaded then this chckbox need to be checked.

Best Regrads, Musaddiq Khan

Musaddiq Khan
  • 1,837
  • 18
  • 16

2 Answers2

2

You can easily do this using the attr command as shown below.

$(".abc").attr('checked', true);

where abc is the name of the class of the check box like

<input type="checkbox" class="abc">

If you want to check it when the page loads just use

       $(document).ready(function() {
           $(".abc").attr('checked', true);
       });
Sunil Kumar P
  • 113
  • 1
  • 11
2

On page-load, you can use the attribute=value selector:

var valueToFind = 3; // or whatever you're looking for
$('input:checkbox[value="' + valueToFind + '"]').prop('checked',true);

JS Fiddle demo.

References:

David Thomas
  • 249,100
  • 51
  • 377
  • 410