Reputation: 103
I want a javascript function to be triggered on key up on any input box. I tried using getElementsByTagName.onkeyup
but it didn't work. Along with the solution please send a working jsfiddle. I don't want document.getElementById
or onkeyup="function()"
as there are many input boxes. It wont look tidy. I even tried
$(document).ready(function(){
$('input').onkeyup(function(){
calculate();
})
})
I also want a function that will add 0 to the value of each input on window.onload. Thank You
Upvotes: 0
Views: 82
Reputation: 388316
Try
$(document).ready(function() {
$(document).on('keyup', 'input', function() {
calculate();
})
})
Demo: Fiddle
Upvotes: 0
Reputation: 75
This should do the keyup part:
$(function() {
$('input').bind('keyup', function() {
alert($(this).attr('id'));
});
});
Upvotes: 0
Reputation: 1
try
document.onkeyup = function () {
if (document.activeElement.tagName.toUpperCase() !== 'input') return;
// do sth. here
}
Upvotes: 0