473,385 Members | 1,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

(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
17 50248
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Matthias Knöchlein | last post by:
hi !! I have the following problem : Is there a function or a constant value to check if a keyCode is a key kile "Shift", "Alt" or "F1". I would like not to use this way : if( ...
1
by: Robert Nurse | last post by:
Hi All, I've got a form which I'm trying to submit automatically when the user has entered 2 or more characters in a text imput box. Here's my set up: <SCRIPT language="JavaScript1.2">...
6
by: Julia Briggs | last post by:
Hi, can someone help me put together a if (event.keyCode function, that will detect when the # character is pressed twice, and then dosomething() ? Sincerely, %Julia%
1
by: Perttu Pulkkinen | last post by:
I have different functions that receive window.event as parameter. Functions are used like this: <input type="text" id="x" onkeypress="return onKeyCurrencyCheck(ev, 'x')" onblur...
6
by: Justin Beasley | last post by:
Here is an answer for those who are looking for a keystroke evaluation script that works in Internet Explorer (IE 5.5, 6.0, 7.0 for PC--IE 4.0, 5.2 for Mac), Mozilla Firefox (Windows, Linux, and...
6
by: rich_poppleton | last post by:
Help.... I've got a textarea where people type in a description. However for certain reasons we need to stop them typing !$*^ . I have a solution this which works fine in IE: function...
4
by: Nathan Sokalski | last post by:
I am writing a piece of code for an ASP.NET function that generates an onKeyPress JavaScript eventhandler that uses the event.keyCode / event.which properties. I have two situations that I would...
10
by: nasir872 | last post by:
I am having trouble in calling tab event using my own function. i call tab event using event.keyCode = 9; but firefox gives this error "Error: event is not defined". What to do? plz help
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.