need if (event.keyCode expert

J

Julia Briggs

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

Evertjan.

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

Randy Webb

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




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

Lee

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

Evertjan.

Randy Webb wrote on 19 mrt 2005 in comp.lang.javascript:
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')
}
 
L

Lee

Evertjan. said:
Randy Webb wrote on 19 mrt 2005 in comp.lang.javascript:


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

Evertjan.

Lee wrote on 19 mrt 2005 in comp.lang.javascript:
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. ;-)
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top