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()));   }); }); 

demo: http://jsbin.com/hivilu/2/


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -