javascript - working with array(s) in JQuery -
i inputting values array in jquery 1,4,7,3. when displaying array values, displays 1,3,4,7.
i need 1,4,7,3 when inserted. code.
var selectedvalues = []; var $ctrls = $("[id*=chkprocessroutes] input:checkbox"); $("[id*=chkprocessroutes] input:checked").each(function () { var l = parsefloat(($ctrls.index($(this)))); var ll = parsefloat(l) + 1; selectedvalues.push(parsefloat(ll)); }); if (selectedvalues.length > 0) { alert("selected value(s): " + selectedvalues.tostring()); } else { alert("no item has been selected."); }
try this:
var selectedvalues = $("[id*=chkprocessroutes] input:checked").map(function () { return $(this).val(); }); if (selectedvalues.length > 0) { alert("selected value(s): " + selectedvalues.tostring()); } else { alert("no item has been selected."); }
Comments
Post a Comment