Activity Forums Salesforce® Discussions How to select all checkboxes of wrapper list on vf page using jquery?

  • How to select all checkboxes of wrapper list on vf page using jquery?

    Posted by Utsav on April 12, 2016 at 7:18 am

    Currently i am using the following function for selecting all checkboxes:

    function checkAll(ele){
    var checkboxes = $('.SelectAll');
    if (ele.checked) {
    $('.checkedone').attr("checked", true);
    }else{
    $('.checkedone').attr("checked", false);
    }
    }

    • This discussion was modified 8 years, 8 months ago by  Utsav.
    • This discussion was modified 8 years, 8 months ago by  Forcetalks.
    • This discussion was modified 8 years, 8 months ago by  Forcetalks.
    • This discussion was modified 8 years, 8 months ago by  Forcetalks.
    • This discussion was modified 8 years, 8 months ago by  Forcetalks.
    • This discussion was modified 8 years, 6 months ago by  Forcetalks.
    Gourav replied 8 years, 6 months ago 3 Members · 4 Replies
  • 4 Replies
  • Sourabh

    Member
    April 12, 2016 at 7:53 am

    Hi Utsav,

    It seems to be working fine for me. Can you please explain exactly what problem you are facing?

  • Utsav

    Member
    April 12, 2016 at 2:23 pm

    Hi ,

    Yes it should work , but when i click on the select all checkbox then it shows an error in browser console that "missing attr".

    But now i think,  i have find out the issue . it actually comes due to the version of jquery i am including. Instead of using "attr" i should use "prop" so now my code will be:

     

    function checkAll(ele){
    var checkboxes = $(‘.SelectAll’);
    if (ele.checked) {
    $(‘.checkedone’).prop(“checked”, true);
    }else{
    $(‘.checkedone’).prop(“checked”, false);
    }
    }

  • Sourabh

    Member
    April 13, 2016 at 4:11 am

    Console shows "missing attr" only if you have not included jquery.  The .prop() method gets the property value for only the first element in the matched set. You can use .prop() as a replacement of .attr() in your case.

  • Gourav

    Member
    June 20, 2016 at 1:53 pm

    Try to use this script in you VF page to select all check-box.

    <script type="text/javascript">
    function selectAllCheckboxes(obj,receivedInputID){
    var inputCheckBox = document.getElementsByTagName("input");
    for(var i=0; i<inputCheckBox.length; i++){
    if(inputCheckBox[i].id.indexOf(receivedInputID)!=-1){
    inputCheckBox[i].checked = obj.checked;
    }
    }
    }
    </script>

Log In to reply.

Popular Salesforce Blogs