How to call a variable from nested function in Jquery -
How to call a variable from nested function in Jquery -
i wanted value of chkarray variable when called outside method.
when called getvalues().total outside method getting error message cannot read property total of undefined.
function getvalues(){ chkarray = new array() ; $("input[type=checkbox]:checked").each(function fire() { var total = chkarray.push($(this).val()); console.log(chkarray) }); };
kindly, help how phone call variable outside method
class="snippet-code-js lang-js prettyprint-override">function getvalues() { var total = new array(); $("input[type=checkbox]:checked").each(function() { total.push($(this).val()); }); homecoming total; }; function dosomething() { var k = getvalues(); console.log(k); }
class="snippet-code-html lang-html prettyprint-override"><script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 1 <input type="checkbox" name="mycheckbox" value="1" /> <br />2 <input type="checkbox" name="mycheckbox" value="2" /> <br />3 <input type="checkbox" name="mycheckbox" value="3" /> <br />4 <input type="checkbox" name="mycheckbox" value="4" /> <br />5 <input type="checkbox" name="mycheckbox" value="5" /> <br /> <input type="button" onclick="dosomething()" value="click me" />
jquery
Comments
Post a Comment