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)">