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

Capturing the backspace key 1

Status
Not open for further replies.

Mighty

Programmer
Feb 22, 2001
1,682
US
Guys,

I am using an onKeyPress event to capture the number/letters that a user is entering into a text field. However, I need to be able to tell if the user has pressed the backspace key to delete some of the input.

Can anyone tell me how to do this?? Mise Le Meas,

Mighty :)
 
Try this function on a page to see what the value of the backspace key is:

function keyDown(e)
{
if (ns4)
{
var nKey = e.which
document.frmBreak.text1.value = "nKey=" + nKey
}
if (ie4)
{
var ieKey = event.keyCode;
document.frmBreak.text1.value = "ieKey=" + ieKey;
}
}


Put this form in the body:

<Form name=&quot;frmBreak&quot;>
<TEXTAREA rows=10 cols=40 id=&quot;textarea1&quot; name=&quot;textarea1&quot;></TEXTAREA><br>
<INPUT type=&quot;text&quot; id=text1 name=text1>
<br><INPUT type=&quot;button&quot; value=&quot;Break&quot; id=button5 name=button5 onclick=&quot;addTags(textarea1.value,'<BR>');&quot;>
<br><INPUT type=&quot;button&quot; value=&quot;Center&quot; id=button6 name=button6 onclick=&quot;addTags(textarea1.value,'<Div align=center> </Div>');&quot;>
</Form>
 
That doesn't show a value when you press the backspace key. Mise Le Meas,

Mighty :)
 
Go here

- click the page 3 radio button

View the source if you want or hit the back space key. The value of the keys you push will appear in a textbox on the page. If you hit the backspace key you might be brought back to the previous page/site you were at. Just hit forward again and the value will be in the textbox.
 
Mithrillhall,

I have the following text box in my form:

<INPUT TYPE=TEXT NAME=&quot;Name&quot; VALUE=&quot;&quot; SIZE=50 onKeyPress=&quot;checkCompany(this.value)&quot;>

For testing purposes, the function only does:

function checkCompany(name)
{
alert(window.event.keyCode);
}

It displays the keyCode for all keys. But when you press the backspace key, it doesn't display anything?!?!?

Am I right to be using the onKeyPress event? Mise Le Meas,

Mighty :)
 
The problem seems to be that I was using the onKeyPress and should have been using the onKeyDown. I have managed to change my function to work using onKeyDown - I hope it stands up OK. Mise Le Meas,

Mighty :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top