Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #7775 > unrolled thread

delete vs period

Started byTim Slattery <Slattery_T@bls.gov>
First post2011-10-28 10:30 -0400
Last post2011-10-29 20:55 +0100
Articles 6 — 5 participants

Back to article view | Back to comp.lang.javascript


Contents

  delete vs period Tim Slattery <Slattery_T@bls.gov> - 2011-10-28 10:30 -0400
    Re: delete vs period Swifty <steve.j.swift@gmail.com> - 2011-10-28 16:24 +0100
    Re: delete vs period Eric Bednarz <bednarz@fahr-zur-hoelle.org> - 2011-10-28 17:57 +0200
    Re: delete vs period Tim Slattery <Slattery_T@bls.gov> - 2011-10-28 12:28 -0400
    Re: delete vs period Antony Scriven <adscriven@gmail.com> - 2011-10-28 09:27 -0700
      Re: delete vs period Dr J R Stockton <reply1143@merlyn.demon.co.uk> - 2011-10-29 20:55 +0100

#7775 — delete vs period

FromTim Slattery <Slattery_T@bls.gov>
Date2011-10-28 10:30 -0400
Subjectdelete vs period
Message-ID<0pela7hpbnnkafvdis9mgk1f86vete3oo5@4ax.com>
I'm trying to make a text input field accept only digits and period,
and only one period. I also want things like delete, left/right arrow,
backspace, home, and end to work.

What I've found is that the event object is different in IE and
Firefox. In IE, I have to use the keyCode property to find out what
was pressed, in Firefox I use charCode.

But...46 is the code for period. But in Firefox's charCode property
that seems also to be the code for the "Delete" key. 

When I get a period, I check the value of the field to determine
whether there's already a period. If there is, I don't allow this
character (return false). Since the charCodes are the same in FF, the
script now disables the Delete key when there's a period in the field.

So how do I tell the difference between period and delete in Firefox?

-- 
Tim Slattery
Slattery_T@bls.gov
http://members.cox.net/slatteryt

[toc] | [next] | [standalone]


#7783

FromSwifty <steve.j.swift@gmail.com>
Date2011-10-28 16:24 +0100
Message-ID<s1ila7pv0v7g9fis9e46l05dqf354fbsdd@4ax.com>
In reply to#7775
On Fri, 28 Oct 2011 10:30:36 -0400, Tim Slattery <Slattery_T@bls.gov>
wrote:

>But in Firefox's charCode property
>that seems also to be the code for the "Delete" key. 

There's something very off going on. I agree that 46 (0X2E) is a
period. 

In my keyboard codes scanner, delete comes in as 224 (0XE0) followed
by 83 (0X53) 

For the "Del" in the numeric keypad that's 0X0053

-- 
Steve Swift
http://www.swiftys.org.uk/swifty.html
http://www.ringers.org.uk

[toc] | [prev] | [next] | [standalone]


#7790

FromEric Bednarz <bednarz@fahr-zur-hoelle.org>
Date2011-10-28 17:57 +0200
Message-ID<m2bot1f6rj.fsf@nntp.bednarz.nl>
In reply to#7775
Tim Slattery <Slattery_T@bls.gov> writes:

> I'm trying to make a text input field accept only digits and period,

So manipulate the value of the field when the keypress event fires.

That also protects you from crippling the user interface; on OS X I use
ctrl+d for delete; incidentally, my keyboard doesn't have a delete key.

-- 
λ

[toc] | [prev] | [next] | [standalone]


#7791

FromTim Slattery <Slattery_T@bls.gov>
Date2011-10-28 12:28 -0400
Message-ID<9nlla71va6l52lvlgehv4ju6kpghflr8ad@4ax.com>
In reply to#7775
Tim Slattery <Slattery_T@bls.gov> wrote:

>I'm trying to make a text input field accept only digits and period,
>and only one period. I also want things like delete, left/right arrow,
>backspace, home, and end to work.
>
>What I've found is that the event object is different in IE and
>Firefox. In IE, I have to use the keyCode property to find out what
>was pressed, in Firefox I use charCode.
>
>But...46 is the code for period. But in Firefox's charCode property
>that seems also to be the code for the "Delete" key. 

After some more experimentation:

onkeypress does not fire in IE for non-character keys like delete,
home, end, arrows, etc. It does fire for those keys in Firefox.

If Firefox, when a character key is pressed (digits, letters, symbols,
something that appears on the screen), charCode contains the
identifying code, keyCode is zero. When a non-character key is
pressed, keyCode has the code and charCode is zero.

So when keyCode == 46 it's the delete key, but when charCode == 46,
it's the "." key.

I'm using IE8 and FF 3.6.16 (I know, I know. Blame my employer, I'm
lucky to have any version of FF at all, even though I'm writing web
systems for the public.)

-- 
Tim Slattery
Slattery_T@bls.gov
http://members.cox.net/slatteryt

[toc] | [prev] | [next] | [standalone]


#7792

FromAntony Scriven <adscriven@gmail.com>
Date2011-10-28 09:27 -0700
Message-ID<7fdedd50-754e-491c-842e-baea1de726cd@4g2000yqu.googlegroups.com>
In reply to#7775
On Oct 28, 3:30 pm, Tim Slattery wrote:

 > I'm trying to make a text input field accept only digits
 > and period, and only one period. I also want things like
 > delete, left/right arrow, backspace, home, and end to
 > work.
 >
 > What I've found is that the event object is different in
 > IE and Firefox. In IE, I have to use the keyCode property
 > to find out what was pressed, in Firefox I use charCode.
 >
 > But...46 is the code for period. But in Firefox's
 > charCode property that seems also to be the code for the
 > "Delete" key.
 >
 > When I get a period, I check the value of the field to
 > determine whether there's already a period. If there is,
 > I don't allow this character (return false). Since the
 > charCodes are the same in FF, the script now disables the
 > Delete key when there's a period in the field.
 >
 > So how do I tell the difference between period and delete
 > in Firefox?

It sounds like you're using onkeypress. Try onkeydown
instead. Alternatively you could let the user input whatever
they like, but display an error if they try to submit the
form (if that's the scenario). That's easier. --Antony

[toc] | [prev] | [next] | [standalone]


#7816

FromDr J R Stockton <reply1143@merlyn.demon.co.uk>
Date2011-10-29 20:55 +0100
Message-ID<B2nPEPELpFrOFwof@invalid.uk.co.demon.merlyn.invalid>
In reply to#7792
In comp.lang.javascript message <7fdedd50-754e-491c-842e-baea1de726cd@4g
2000yqu.googlegroups.com>, Fri, 28 Oct 2011 09:27:31, Antony Scriven
<adscriven@gmail.com> posted:

>It sounds like you're using onkeypress. Try onkeydown
>instead. Alternatively you could let the user input whatever
>they like, but display an error if they try to submit the
>form (if that's the scenario). That's easier. --Antony

It depends a little on the application.

A professional data entry clerk may like to have characters typed in one
by one and immediately checked for acceptability.

That, implemented literally, would not help those who enter with
copy'n'paste or drag'n'drop.

Sometimes, users really benefit from being able to copy anything into
the field, and then editing until right, then signifying completion, at
which stage validation can be appropriate.

-- 
 (c) John Stockton, nr London UK. ?@merlyn.demon.co.uk  BP7, Delphi 3 & 2006.
   <http://www.merlyn.demon.co.uk/> TP/BP/Delphi/&c., FAQqy topics & links;
   <http://www.bancoems.com/CompLangPascalDelphiMisc-MiniFAQ.htm> clpdmFAQ;
   NOT <http://support.codegear.com/newsgroups/>: news:borland.* Guidelines

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.javascript


csiph-web