By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,776 Members | 1,387 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,776 IT Pros & Developers. It's quick & easy.

need if (event.keyCode expert

P: n/a
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%

Jul 23 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Julia Briggs wrote on 19 mrt 2005 in comp.lang.javascript:
Hi, can someone help me put together a if (event.keyCode function, that
will detect when the # character is pressed twice, and then
dosomething() ?


<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()'>
--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Jul 23 '05 #2

P: n/a
Evertjan. wrote:
Julia Briggs wrote on 19 mrt 2005 in comp.lang.javascript:

Hi, can someone help me put together a if (event.keyCode function, that
will detect when the # character is pressed twice, and then
dosomething() ?

<script type='text/javascript'>

var n=0

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


if (n==2){alert('2 x #');n = 0}

better maybe?

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Jul 23 '05 #3

P: n/a
Randy Webb wrote on 19 mrt 2005 in comp.lang.javascript:
Evertjan. wrote:
Julia Briggs wrote on 19 mrt 2005 in comp.lang.javascript:

Hi, can someone help me put together a if (event.keyCode function,
that will detect when the # character is pressed twice, and then
dosomething() ?

<script type='text/javascript'>

var n=0

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


if (n==2){alert('2 x #');n = 0}

better maybe?


No, I dont think so.

Why improve on a OQ we don't know the reason of.

================

Perhaps two or more consecutive #'es are ment,
but also that is not asked.

function x(){
if(event.keyCode==35) n++ else n=0
if (n>=2) alert('2 or more #\'s consecutive')
}

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

Jul 23 '05 #4

P: n/a
Lee
Randy Webb said:

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

Hi, can someone help me put together a if (event.keyCode function, that
will detect when the # character is pressed twice, and then
dosomething() ?

<script type='text/javascript'>

var n=0

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


if (n==2){alert('2 x #');n = 0}

better maybe?


Better, but without knowing what the OP really wants to detect,
we don't know if it really does the job. If it's to prevent two
#'s from being entered in a single field, for example, it would
have to check the whole field value after each keystroke.

And of course, it would be much better to audit for that onchange.

Jul 23 '05 #5

P: n/a
Lee
Evertjan. said:

Randy Webb wrote on 19 mrt 2005 in comp.lang.javascript:
Evertjan. wrote:
Julia Briggs wrote on 19 mrt 2005 in comp.lang.javascript:
Hi, can someone help me put together a if (event.keyCode function,
that will detect when the # character is pressed twice, and then
dosomething() ?

<script type='text/javascript'>

var n=0

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


if (n==2){alert('2 x #');n = 0}

better maybe?


No, I dont think so.

Why improve on a OQ we don't know the reason of.


Why try to guess at answers to an OQ you don't understand?

Jul 23 '05 #6

P: n/a
Lee wrote on 19 mrt 2005 in comp.lang.javascript:
Why improve on a OQ we don't know the reason of.


Why try to guess at answers to an OQ you don't understand?


It is quite possible to understand a Q
without understanding for what purpose that Q is asked.

Improving on such Q however is out of the Q, Lee. ;-)

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

Jul 23 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.