My counter function looks like that
function count() {
var value = ids.val();
return (value == '') ? 0 : value.replace(/\s,?|,$/g, '').split(',').length;
}
Then checking for returned value and posting data via ajax
if(count() === 10){
ajaxPost();
$(ids).val('');
}
I set interval to use this function. Noting that, tried all other function like change(),paste().. the only way that worked with my scanner device is, to set interval.
The problem is, when i type 9 numbers, like 1…9 and then want to type 10, when I press 1 to write 10 right after 9, it directly posts data. doesn’t wait for “,”. How can I modify it to wait for “,” after last (in this case 10th) word?
You can check the key pressed and see if it is a comma, then only run your code after it is known that the last key entered was a comma: