javascript - Jquery - Javascipt, checked checkbox by value which is the value is part of array -


i have lot of checkbox have value this

<input  name="selection[]" value="2282,2283,2284,2285,2286,2287,2288,2289,2290,2298,2299,2300" type="checkbox">  <input name="selection[]" value="1429,1432,1450,1451,1462,1469" type="checkbox">  <input name="selection[]" value="667,669,679,683,685,686,687" type="checkbox"> 

if have array named temp whic have data this:

array [ 2282, 2283, 2284, 2285, 2286, 2287, 2288, 2289, 2290, 2298, 2299 , 2300 ] 

how can checked checkbox have value stringify of array, in case first checkbox ?

so far, code :

$(document).on('pjax:complete', function(data){        var temp = $('#print-sticker-keren').attr('data-print').split(',').map(number);                   // array : array [ 2282, 2283, 2284, 2285, 2286, 2287, 2288, 2289, 2290, 2298, 2299 , 2300 ]           (i=0; i!=temp.length;i++) {             var checkbox = $("input[type='checkbox'][value='"+temp[i]+"']");             checkbox.attr("checked","checked");         }      }); 

please advise

updated answerd.

$(document).on('pjax:complete', function(data){         var temp = $('#print-sticker-keren').attr('data-print').split(',').map(number);         var checkbox = $("input[type='checkbox'][name='selection[]']");           (var = 0; < checkbox.length; i++) {             var coba = $(checkbox[i]).val().split(',').map(number); // checkbox[i].val not function              (var j = 0; j < coba.length; j++) {                var ins = $.inarray(coba[j], temp);                 if(ins !== -1){                    $(checkbox[i]).attr("checked","checked");                }             }         }     }); 


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -