i have a div that is load dynamically into my page with an ajax request.
In this div i have severall input all with the same class but different ID’s
Those inputs have a keyup function, a keypress function and a onblur function.
The problem is i want that the user only can type in numbers and use the TABULATOR.
I use this function here
function validatenum(event) {
var key = window.event ? event.keyCode : event.which;
if (event.keyCode == 8 || event.keyCode == 9 || event.keyCode == 46
|| event.keyCode == 37 || event.keyCode == 39
) {
return true;
} else if (key < 48 || key > 57) {
return false;
} else {
return true;
}
}
and I call it with:
<input type="text" id="31_w_pr" class="order_sizes"
onkeypress="validatenum(event);" />
But it doesn’t work. I can type in whatever I want.
Does anyone have an idea as to how to fix this?
Thanks
Try:
Try it here: http://jsfiddle.net/andrewwhitaker/afqf9/
However, consider separating your JavaScript and HTML.