Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

text box numeric

Status
Not open for further replies.

tester321

Programmer
Mar 13, 2007
150
CA
Howdy, can't seem to get it working....am i missing something here? thanks

... onKeyDown="if (checkNum(this.value)==false){this.value='0';alert('Numeric values only.');}" ...

<script>
function checkNum(val) {
alert(val);
return (/^[0-9]+$/.test(val));
}
...
 
I think I know what the problem is. Put the function call onkeyup, not onkeydown. Onkeydown, you are checking BEFORE the current pressed key's value is entered.

Besides that, all looks good (to me at least)

[monkey][snake] <.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top