From: Julia Briggs on
Are there any gotchas using if (event.keyCode==8)? I understand that
to represent backspace, but it doesn't work. I am running Windows XP,
using a typical keyboard - but no luck in detecting backspaces. Anyone
have experiences with this?

From: Evertjan. on
Julia Briggs wrote on 21 mrt 2005 in comp.lang.javascript:

> Are there any gotchas using if (event.keyCode==8)? I understand that
> to represent backspace, but it doesn't work. I am running Windows XP,
> using a typical keyboard - but no luck in detecting backspaces. Anyone
> have experiences with this?

Unless an <input> field is in focus,
BS is a reserved key for one page back.

--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

From: Julia Briggs on
Ah! I (think) I am following you. When I say backspace, I actually
mean the delete key. How would you replace in your snippet below to
detect a single delete and then dosomething(). I *really* appreciate
your time.

%Julia%


<script type='text/javascript'>

var n=0


function x(){
if(event.keyCode==35){
n+=1
if (n==2)alert('2 x #')
}

}


</script>

<input onkeypress='x()'>

From: RobG on
Julia Briggs wrote:
> Ah! I (think) I am following you. When I say backspace, I actually
> mean the delete key. How would you replace in your snippet below to
> detect a single delete and then dosomething(). I *really* appreciate
> your time.

This will help you work out keyCodes (it also works in more
browsers than just IE):

<script type="text/javascript">
function sayKeyCode(event, v){
document.getElementById(String(event.type)).innerHTML =
'Value on ' + event.type + ': ' + v
+ ' KeyCode: ' + event.keyCode;
}
</script>

<input type="text" size="10"
onkeyup="sayKeyCode(event,this.value);"
onkeydown="sayKeyCode(event,this.value);"><br>
<span id="keydown"></span><br>
<span id="keyup"></span>



'Delete' is keyCode 46.

If you want to intercept the key before anything happens, use
onkeydown. If you want to do something after the key has done
whatever to the field, use onkeyup.

[...]
>
> function x(){

Need to capture event (see below):

function x(event){

> if(event.keyCode==35){
> n+=1
> if (n==2)alert('2 x #')
> }
[...]
>
> <input onkeypress='x()'>

If you don't pass 'event', it will not work in Firefox

<input onkeypress='x(event)'

Passing 'event' does not affect IE, it just adds support for
those browsers that support the alternative Mozilla event model.


--
Rob
From: Evertjan. on
Julia Briggs wrote on 21 mrt 2005 in comp.lang.javascript:

> Ah! I (think) I am following you.

Well we cannot follow you if you don't quote, Julia.

This is not email but usenet, so follow netiquette.

> When I say backspace, I actually mean the delete key.

Please say what you mean.
Programming is a strict technology.

--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

 |  Next  |  Last
Pages: 1 2 3
Prev: XmlHttpRequest & responseXml
Next: isNum