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 Chriss 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
Joined
Mar 13, 2007
Messages
150
Location
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));
}
...
 
What errors do you get? Do you see either alert? Have you tried looking in the JS console in Firefox or using Firebug to see if any errors are thrown?

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
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