brgdotnet
asked on
How to filter by key press ?
I have a requirement to have a text box control, on a web form. The requirements states that the
application user will only be able to delete text from the text box and nothing else. So in other words
I only want it so that the delete button is recognized when that key is pressed. All of the other keyboard keys will not work in the text box control. How can I enforce this? I imagine I would use Java script somehow, but that is all I can think of. Can someone help me out? Possibly you have some code to share as an example.
For example suppose the page loads and my textbox control has three words in it : I like Sushi
the cursor will be placed at the end of the text box and the user can press the delete button to delete a character at a time. How can I do that?
I am using Asp.net with web forms.
application user will only be able to delete text from the text box and nothing else. So in other words
I only want it so that the delete button is recognized when that key is pressed. All of the other keyboard keys will not work in the text box control. How can I enforce this? I imagine I would use Java script somehow, but that is all I can think of. Can someone help me out? Possibly you have some code to share as an example.
For example suppose the page loads and my textbox control has three words in it : I like Sushi
the cursor will be placed at the end of the text box and the user can press the delete button to delete a character at a time. How can I do that?
I am using Asp.net with web forms.
ASKER
I have googled and have not found a suitable solution. I need expert help.
Please find small example below:
HTML:
HTML:
<input type="text" onkeypress='deleteText(event)'>
Javascript:
function deleteText(event){
//8 for backspace and 46 for delete
if (event.keyCode == 8 || event.keyCode == 46)
{
return true; //return true if backspace or delete pressed
}else{
return false; //else return false
}
}
Hope you get your resolution!
ASKER
Thanks Prakash, the Java script you showed my catches the key press, however I have no idea how to suspend the key press for a particular keyboard key?
If you are anyone else has any ideas, I would sure appreciate it. Thanks.
If you are anyone else has any ideas, I would sure appreciate it. Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
So awesome. Works great. You saved me, thanks.
If you google, you will find several implementations, such as this.