119
rated 0 times
[
122]
[
3]
/ answers: 1 / hits: 43664
/ 12 Years ago, fri, july 13, 2012, 12:00:00
The Question
To help avoid end-user confusion, I want to add an alert message that pops up if/when the user clicks any other key [alert('Only Numerical data allowed')]. So if they press the 'k' the above message will pop up. Can anyone see how to set this code within this code base
- jsfiddle: http://jsfiddle.net/EN8pT/4/
The Code
jquery:
$('input.numberinput').bind('keypress', function (e) {
var w = e.which;
return (w != 8 && w != 0 && (w < 48 || w > 57) && w != 46) ? false : true;
});
html
<div class=containercontent>
<div class=label>Enter a number:</div>
<input type=text name=txtNumber1 id=txtNumber1 value= class=numberinput />
<div class=label>Enter a number:</div>
<input type=text name=txtNumber2 id=txtNumber2 value= class=numberinput />
</div>
More From » jquery