0

I can enable and check all the fields on my form, but I can't have the fields enabled automatically! This is my code (now working):

    $(document).ready(function(){

        $("#lnk_checkall").click(function() {
            if ($(this).attr("checked"))
            {
                $("input:checkbox.fb_chk").attr("checked", "checked");
                $("input:checkbox.fb_chk").trigger("change");
            }
            else
            {
                $("input:checkbox.fb_chk").removeAttr("checked");
                $("input:checkbox.fb_chk").trigger("change");
            }
        });

        $("tr.photo_fb_item .fb_chk").change(function() {
            var parent = $(this).parent().parent();
            if ($(this).attr("checked") == "checked")
            {
                $("input.d", parent).removeAttr("disabled");
                $("textarea.d", parent).removeAttr("disabled");
            }
            else
            {
                $("input.d", parent).attr("disabled", "disabled");
                $("textarea.d", parent).attr("disabled", "disabled");
            }

        });

    });

and this is my page:

                $out .= '<input type="checkbox"  name="checkall" id="checkall">Select All<br>';

                $out .= '<tr class="photo_fb_item">'
                    . '<td><input type="checkbox" class="fb_chk" name="PICSOURCE[]" value="' . $item['source'] . '"/>'

can anyone add me the code to check all the boxes, please?

THelper
  • 15,333
  • 6
  • 64
  • 104

1 Answers1

0
$(this).prop("checked", true);

should be able to check your checkbox for more details on this please refer the following post

Setting "checked" for a checkbox with jQuery?

EDIT

code to check all fields if checkall is enabled uncheck otherwise

$('#checkall').click(function() {
  if($(this).attr('checked')== true) {
    $('.fb_chk').each(function() { 
     $(this).prop("checked", true); 
    }) 
  }
  else {
    $('.fb_chk').each(function() { 
     $(this).prop("checked", false); 
    }) 
  }
 })
Community
  • 1
  • 1
optimusprime619
  • 754
  • 2
  • 17
  • 38
  • I need a new function that will check all my checkboxes when I select the "select all" checkbox... – user1202494 Feb 11 '12 at 10:30
  • add the following code to your Select All checkbox's on click event `$('#checkall').click(function() { $('.fb_chk').each(function() { $(this).prop("checked", true); }) })` that should do the job. – optimusprime619 Feb 11 '12 at 10:35
  • almost there... now I can check all the checkboxes, but the fields are not automatically enabled... thank you for the help! :) – user1202494 Feb 11 '12 at 10:46
  • if its fixed, kindly mark the question answered as it will help others searching with similar queries – optimusprime619 Feb 11 '12 at 10:51
  • This answer is quite ready yet. Use `if($(this).prop('checked'))` instead of `if($(this).attr('checked') == true)`. jQuery versions that have `.prop` (1.6+) have `attr('checked') == 'checked'`, not `attr('checked') == true`. See http://api.jquery.com/prop/ – ori Feb 11 '12 at 11:25