javascript - Checkbox variable outside of function -
i new coding (trying learn) , cant figure out how var of check box value outside of function.
javascript:
$(document).ready(function() { var quantity= parseint($('#phones').val()); $("#check1 input:checkbox").change(function() { var feature = 0; $("#check1 input:checkbox").each(function() { if ($(this).is(':checked')) { feature += parseint($(this).prop('value')); } }); }); var grand = feature * (quantity * number ('0.1')) var total = quantity + grand });
html:
<input id="phones" type="numerical" value="0" style="text-align: right"/> <div id="check1"> <input type="checkbox" value="1" />
function getresult(feature, phones) { if (feature <= 0 || phones <= 0) { return 'error...., enter number of phones , check checkbox'; } return (feature * (+phones * 0.1)) + +phones; } function getfeature() { var feature = 0; $('#check1 input:checkbox:checked').each(function () { feature += +$(this).prop('value') || 1; }); return feature; } $(document).ready(function() { var $phones = $('#phones'), $result = $('#result'); $("#check1 input:checkbox").change(function() { $result.html(getresult(getfeature(), $phones.val())); }); $("#phones").keyup(function() { $result.html(getresult(getfeature(), $phones.val())); }); });
Comments
Post a Comment