jquery - Count many text inputs and do something when each is set -
i have many many textbox inputs on page, i'm attempting check each set in loop, when each set i'm attempting run function.
i have following code:
$( document ).ready(function() { var count_input = 0; var count_valid_input = 0; $("#weekly-suppliers").change(function(){ call_calculation(); // }); function call_calculation(){ $('input[class=enquiry]').each(function(){ count_input ++; var text_value = $(this).val(); if(text_value != '') //remember, data has been sanitized! { count_valid_input ++; console.log('input: ' + count_input); console.log('valid: ' + count_valid_input); } }) if(count_input == count_valid_input){ console.log('do calc'); do_calculation(); } else { count_input = 0; count_valid_input = 0; } } });
this loops through each text input class enquiry. counter incremented each element, counter initiated each element set. if these 2 counters match, function run. i'm nevver reaching point though, suggest why?
the function call_calculation called in each text input change event. have lots of these functions in script, each text input:
$("#weekly-suppliers").change(function(){ call_calculation(); // });
so when number of valid inputs matches number of text inputs class enquiry
, function do_calculation();
should called, never met. suggest why?
Comments
Post a Comment