467,885 Members | 1,355 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,885 developers. It's quick & easy.

(event.keyCode==8) BACKSPACE problems

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?

Jul 23 '05 #1
  • viewed: 49489
Share:
17 Replies
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)

Jul 23 '05 #2
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()'>

Jul 23 '05 #3
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)).innerH TML =
'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
Jul 23 '05 #4
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)

Jul 23 '05 #5
Evertjan. wrote on 21 mrt 2005 in comp.lang.javascript:
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.


I take this back/I delete this.
The bottom part of your message, seems to be the quote.
When I say backspace, I actually mean the delete key.


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


RobG already informed you on the delete keycode,
and mark his response style.
--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Jul 23 '05 #6
Hi there. Thank you for your original solution (which worked for me).
My new problem is trying to get it to detect the keyboard backspace
key. I made a mistake calling it a delete key.

You mentioned "Unless an <input> field is in focus, BS is a reserved
key for one page back.", which clues me in to this issue. How/what does
this work in this situation? Could you please show an example?

Sincerely, Julia.

Jul 23 '05 #7
Julia Briggs wrote on 21 mrt 2005 in comp.lang.javascript:
Hi there. Thank you for your original solution (which worked for me).
My new problem is trying to get it to detect the keyboard backspace
key. I made a mistake calling it a delete key.

You mentioned "Unless an <input> field is in focus, BS is a reserved
key for one page back.", which clues me in to this issue. How/what does
this work in this situation? Could you please show an example?

Sincerely, Julia.


Dear Julia,

This is usenet, not email.

Others want to read and possibly comment too.

So if you persist in not(!) quoting relevant part
of the posting you reply upon
that is considered rude to the NG community.

If you don't conform to this 20 year old netiquette/custom,
I won't reply to your questions.

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

Jul 23 '05 #8
Hi there. Thank you for your original solution (which worked for me).
My new problem is trying to get it to detect the keyboard backspace
key. I made a mistake calling it a delete key.

You mentioned "Unless an <input> field is in focus, BS is a reserved
key for one page back.", which clues me in to this issue. How/what does

this work in this situation? Could you please show an example?

Sincerely, Julia.

(Sorry Evertjan, I will work on that. Thank you for the Netiquette
lesson.)

Jul 23 '05 #9
Julia Briggs wrote:
Hi there. Thank you for your original solution (which worked for me).
My new problem is trying to get it to detect the keyboard backspace
key. I made a mistake calling it a delete key.
'it' being an input field? The document body?

The code snippet I posted earlier gives you an input that
reports the keyCode of whatever key is pressed. Use it to find
out what the keyCode is for any key pressed.

If you want to detect 'backspace' anywhere in the document, use
an onkeydown event with the body element to capture it.

You mentioned "Unless an <input> field is in focus, BS is a reserved
key for one page back.", which clues me in to this issue. How/what does
this work in this situation? Could you please show an example?
In what situation? If an input is in focus, the backspace key
will be passed to the input form control, which will delete a
character if there is one immediately before the current cursor
position, or do nothing if not.

If an input or textarea or some other editable element is not in
focus, the browser will capture the keydown and *maybe* navigate
back to the previous history entry if there is one. If there
isn't one, it wont.

Sincerely, Julia.

(Sorry Evertjan, I will work on that. Thank you for the Netiquette
lesson.)


Actions speak louder than text?
--
Rob
Jul 23 '05 #10
Thanks Rob for the gang-up. Did you get my e-mail thanking you earlier
or did Google not send it to you? ...............

Jul 23 '05 #11
Julia Briggs wrote:
Thanks Rob for the gang-up. Did you get my e-mail thanking you earlier
or did Google not send it to you? ...............


It is usual to reply via the newsgroup unless specifically asked
to respond with email. The idea of the group is that many people
can view posts, which is useful for learning and also posting
responses.

The group FAQ is here:

<URL:http://www.jibbering.com/faq/>

Please read #2.3 in particular.

Having been around this group for a little while, you will have
read through a number of threads and can see the style of
response that is preferred and how various posters add to the
knowledge passed on by previous posters by offering
improvements, alternatives and corrections.

If you annoy participants by not following established group
etiquette, they will stop responding to or even reading your
posts. Most newsreaders can be set to ignore posts from certain
users so that their posts don't appear at all.

The group's guidelines are pretty much the same as those that
have been established by news group users in general over many
decades and are fundamental to the smooth running of the group.
Deliberately ignoring them means that you donít value the
opinion of the people who developed them (i.e. the participants
in the group).

If you donít value their opinion or respond to their (quite
reasonable) requests to follow the group etiquette when posting,
why should they answer your questions?
--
Rob
Jul 23 '05 #12
Uh, thanks for that response.... but isn't the spirit of this group to
help people who are in need, from people more knowledgeable, ....... so
then why are you standing on a soapbox quoting etiquette and acting
like a complete ass???? My approach from start one was genuine. I am
sorry I didn't include the original quote in my earlier response. But
I digress........I think you are absolutely and hopelessly lost
responding to my words on the screen and not taking it light,
misunderstanding them as you are. That is one tip for life. Maybe you
don't care to think it's important, but who cares anyway huh?

Anyway.

Jul 23 '05 #13
Julia Briggs wrote:
Uh, thanks for that response.... but isn't the spirit of this group to
help people who are in need, from people more knowledgeable, ....... so
then why are you standing on a soapbox quoting etiquette and acting
like a complete ass???? My approach from start one was genuine. I am
sorry I didn't include the original quote in my earlier response. But
I digress........I think you are absolutely and hopelessly lost
responding to my words on the screen and not taking it light,
misunderstanding them as you are. That is one tip for life. Maybe you
don't care to think it's important, but who cares anyway huh?

Anyway.


You did it again!!!
Mick
Jul 23 '05 #14

Keith Thompson wrote in comp.lang.c, message ID
<ln************@nuthaus.mib.org> :-
If you want to post a followup via groups.google.com, don't use
the "Reply" link at the bottom of the article. Click on "show options"
at the top of the article, then click on the "Reply" at the bottom of
the article headers.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME ©
Web <URL:http://www.uwasa.fi/~ts/http/tsfaq.html> -> Timo Salmi: Usenet Q&A.
Web <URL:http://www.merlyn.demon.co.uk/news-use.htm> : about usage of News.
No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.
Jul 23 '05 #15
Lee
Julia Briggs said:

Uh, thanks for that response.... but isn't the spirit of this group to
help people who are in need, from people more knowledgeable, ....... so
then why are you standing on a soapbox quoting etiquette and acting
like a complete ass????


If we don't correct people who don't use the correct etiquette,
this newsgroup would degenerate into something that none of us
would want to read.

Several people have tried to help you. It's not clear what else
you need. If you are trying to prevent two "#" characters from
being entered in to a form field, I'll repeat that you don't want
to do that by examining individual keystrokes.

Jul 23 '05 #16
JRS: In article <11**********************@o13g2000cwo.googlegroups .com>
, dated Mon, 21 Mar 2005 21:59:07, seen in news:comp.lang.javascript,
Julia Briggs <ju*******@yahoo.com> posted :
Uh, thanks for that response.... but isn't the spirit of this group to
help people who are in need, from people more knowledgeable, ....... so
then why are you standing on a soapbox quoting etiquette and acting
like a complete ass???? My approach from start one was genuine. I am
sorry I didn't include the original quote in my earlier response. But
I digress........I think you are absolutely and hopelessly lost
responding to my words on the screen and not taking it light,
misunderstanding them as you are. That is one tip for life. Maybe you
don't care to think it's important, but who cares anyway huh?


If you want skilled persons who prefer particular standards and
practices to help you, then it behoves you to conform with those
standards.

Regulars find proper quoting to be helpful; therefore, if you want help
from regulars, you should quote properly. See references below.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME ©
Web <URL:http://www.uwasa.fi/~ts/http/tsfaq.html> -> Timo Salmi: Usenet Q&A.
Web <URL:http://www.merlyn.demon.co.uk/news-use.htm> : about usage of News.
No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.
Jul 23 '05 #17
JRS: In article <P7****************@news.optus.net.au>, dated Tue, 22
Mar 2005 04:26:23, seen in news:comp.lang.javascript, RobG
<rg***@iinet.net.auau> posted :

The group FAQ is here:

<URL:http://www.jibbering.com/faq/>

Please read #2.3 in particular.

That is now a year old; many suggestions for improvements have been made
since a year ago - so many that it's statistically certain that there
are some good ones among them.

One such suggestion has, IIRC, been to add advice to #2.3 for those
unwise to use new Google for news, in order that they may know what to
do to get quoting as it should be.
ISTM that it would be beneficial to retain the present Monday and
Wednesday posting of the neat-and-tidy FAQ, and to substitute for the
Friday posting a "rough draft changes list" in simple plain-text format.
As soon as a suitable suggestion was seen, it could then be
copy'n'pasted into the master with minimal editing, and the master could
be uploaded to the distribution point once a week.

Similarly, acceptable suggestions for changes to the draft could be
added immediately, and edited in whenever convenient. Once an item had
been at the top of the list for a while, it would presumably be ripe for
moving into the FAQ proper with only editorial work.

That should make presenting new material much easier and therefore
faster.
A FAQ Note on Accessibility could be useful.

Part would link to existing notes on, for example, browser detection and
square-bracket notation and supplying a getElementById. There'd be
references to DAA, ADA, ... . There'd be reasons against absolute
sizing. There'd be ... ?

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #18

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Matthias KnŲchlein | last post: by
1 post views Thread by Robert Nurse | last post: by
6 posts views Thread by Julia Briggs | last post: by
1 post views Thread by Perttu Pulkkinen | last post: by
6 posts views Thread by Justin Beasley | last post: by
6 posts views Thread by rich_poppleton | last post: by
reply views Thread by MrMoon | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.