[Solved] Select a checkbox by comparing two arrays [closed]


Try this out:- http://jsfiddle.net/adiioo7/zhEB2/9/

First of all it should be $('.divPrintDetailed table') instead of $(#divPrintDetailed table') and for iterating in the idArray first parameter is index and second is the element.

JS:-

function CheckboxSelect() {
    var idArray = [];
    var idContainerArray = [];

    idContainerArray[0] = "tbl-10-486011";
    idContainerArray[1] = "tbl-10-486013";
    idContainerArray[2] = "tbl-10-486016";

    $('.divPrintDetailed table').each(function (i, e) {
        idArray.push($(e).attr('id'));
    });

    //alert(idArray.length);

    $.each(idArray, function (index, el) {
        alert(el.slice(4));
        if ($.inArray(el, idContainerArray) != -1) {
            $('#' + el.slice(4)).prop("checked", "checked");
        }
    });
}

$('#btnSubmit').click(function () {
    CheckboxSelect();
});

HTML:-

<div class="divPrintDetailed">
    <table  id="tbl-10-486011" data-ordernum="0">
   <tr>    <td> 
     <input class="containerToCopy" id="10-486011" type="checkbox">   </td>       </tr>
        </table>
         <table  id="tbl-10-486012" data-ordernum="1">
             <tr>    <td>  <input class="containerToCopy" id="10-486012" type="checkbox">     </td>       </tr>
             </table>
         <table  id="tbl-10-486013" data-ordernum="2">
             <tr>    <td>  <input class="containerToCopy" id="10-486013" type="checkbox">     </td>       </tr>
             </table>
         <table  id="tbl-10-486014" data-ordernum="3">
             <tr>    <td>  <input class="containerToCopy" id="10-486014" type="checkbox">     </td>       </tr>
             </table>
         <table  id="tbl-10-486015" data-ordernum="4">
             <tr>    <td> <input class="containerToCopy" id="10-486015" type="checkbox">      </td>       </tr>
             </table>
         <table  id="tbl-10-486016" data-ordernum="5">
             <tr>    <td> <input class="containerToCopy" id="10-486016" type="checkbox">      </td>       </tr>
             </table>
             </div>
             <button type="button" id="btnSubmit" >Click Me!</button>

solved Select a checkbox by comparing two arrays [closed]