I have an input type number. I know how to call a function when I press the enter key.
Please see my code:
<input type="number" class="new_num" value="0"> <input type="number" class="new_num_2" value="0"> <script> $('.new_num').bind("enterKey",function(e) { alert($(".new_num").val()); }); $('.new_num').keyup(function(e){ if(e.keyCode == 13) { $(this).trigger("enterKey"); } }); </script>
Now I need to warn the value when the user simply presses the up or down arrow on the number. I wrote this code, but it did not work:
$('.new_num').bind('keyup input', function(){ $(this).trigger("enterKey"); });
Please, help.
Also I need to do the same operation for new_num_2 . Do I need to duplicate the code?
What code do I need to write if the user is using a mobile device?
source share