Hello,
Can somebody tell me if into my 'input' I'd like to accept only just the number type, how can I handling this with use the 'style' from the stylesheet elements?
This solution will prevent anything but digits as the user types:
function numOnly(event, field)
{
var eventKey, keychar;
if (window.event)
{
eventKey = window.event.keyCode;
}
else if (event)
{
eventKey = event.which;
}
else
{
return true;
}
//turn the event code into a real character
keychar = String.fromCharCode(eventKey);
//if it's a number we'll work with it, otherwise we won't
if (("0123456789".indexOf(keychar) > -1)
{
return true;
}
//no number entered, don't accept it
//you can also insert an alert if you
//want users to know they can enter only digits
//As is, if the user types a non-digit, nothing
//happens at all
else
{
return false;
}
}
The call looks like this:
<input type="text" name="txtBox" onkeypress=" return numOnly(event, this)">
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.