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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to clear a value entered in text box if it is not alphabetic

Status
Not open for further replies.

pkelly2003

Technical User
Feb 14, 2003
4
US
Question: On the client side, how do I automatically clear a value entered into a form text box if it is not alphbetic (not a letter)?
 
More specifically, I want to clear any numbers entered (as they are entered - before the form is even submitted).
 
I tried that but it still entered the number that the user enters. I am using a function to check for numbers being entered using window.event.keycode. Here is what I have so far:

function checkKey
if (window.event.keyCode < 65) or (window.event.keyCode > 90) and (window.event.keyCode < 97) or (window.event.keyCode > 122) then
msgbox &quot;Please enter only letters in this box.&quot;, vbCancel
else

end if

end function

The form contains the following:
<input type=&quot;text&quot; name=&quot;Fname&quot; id=fname size=&quot;20&quot; onkeypress=&quot;checkKey&quot;><P>

The problem is that I can't prevent the number from being displayed in the form. How do I program something behind the 'Cancel' button (vbCancel) to prevent the number from being accepted and displayed?

 
I found my own answer!

I just needed to add this line to the function to make it work:
window.event.keycode = &quot;&quot;

-pk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top