(event.keyCode==8) BACKSPACE problems

J

Julia Briggs

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?
 
E

Evertjan.

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.
 
J

Julia Briggs

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()'>
 
R

RobG

Julia said:
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.
 
E

Evertjan.

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.
 
E

Evertjan.

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


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.
Please say what you mean.
Programming is a strict technology.

RobG already informed you on the delete keycode,
and mark his response style.
 
J

Julia Briggs

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.
 
E

Evertjan.

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.
 
J

Julia Briggs

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.)
 
R

RobG

Julia said:
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?
 
J

Julia Briggs

Thanks Rob for the gang-up. Did you get my e-mail thanking you earlier
or did Google not send it to you? ...............
 
R

RobG

Julia said:
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?
 
J

Julia Briggs

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.
 
M

Mick White

Julia 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???? 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
 
D

Dr John Stockton

Keith Thompson wrote in comp.lang.c, message ID
<[email protected]> :-
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.
 
L

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.
 
D

Dr John Stockton

JRS: In article <[email protected]>
, dated Mon, 21 Mar 2005 21:59:07, seen in
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???? 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.
 
D

Dr John Stockton

JRS: In article <P7N%[email protected]>, dated Tue, 22
Mar 2005 04:26:23, seen in RobG
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 ... ?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top