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


Groups > comp.lang.javascript > #10374

Re: How to set 'onKeyPress ...' programmatically ?

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!tudelft.nl!txtfeed1.tudelft.nl!multikabel.net!newsfeed20.multikabel.net!amsnews11.chello.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post2.news.xs4all.nl!newszilla.xs4all.nl!not-for-mail
Newsgroups comp.lang.javascript
Subject Re: How to set 'onKeyPress ...' programmatically ?
From "Evertjan." <exjxw.hannivoort@interxnl.net>
References <9np0guFpjtU1@mid.individual.net> <Xns9FDEF353B131Deejj99@194.109.133.133> <9np21iF4v2U1@mid.individual.net>
Message-ID <Xns9FDF6BFAC416eejj99@194.109.133.133> (permalink)
User-Agent Xnews/2009.05.01
Date 18 Jan 2012 23:39:49 GMT
Lines 41
NNTP-Posting-Host 188.142.37.124
X-Trace 1326929989 dreader34.news.xs4all.nl 19713 ehannivo/188.142.37.124:57119
Xref x330-a1.tempe.blueboxinc.net comp.lang.javascript:10374

Show key headers only | View raw


Mel Smith wrote on 19 jan 2012 in comp.lang.javascript:

> "Evertjan." <exjxw.hannivoort@interxnl.net> wrote in message 
> news:Xns9FDEF353B131Deejj99@194.109.133.133...
>> something like, [not tested]:
>>
>> var inputs = document.forms[0].getElementsByTagName('input');
>> for (i=0;i<inputs.length;i++)
>>    inputs[i].onKeyPress = myFunction;
> 
> Hi Evertjan:
> 
>     Here is what I started with below

If something does not work, don't start with such complex code,
try the most simple one, and then go debugging

It turns out that the onkeypress should be all lowercase:

Tested in Chrome:
============================
<input id=a><br>
<input id=b><br>
<input id=c><br>

<script type='text/javascript'>
 var inputs = document.getElementsByTagName('input');
 for (i=0;i<inputs.length;i++)
    inputs[i].onkeypress = f;

 function f() {
    alert(this.id);
 };
</script>
============================


-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

How to set 'onKeyPress ...' programmatically ? "Mel Smith" <med_cutout_syntel@aol.com> - 2012-01-18 15:47 -0700
  Re: How to set 'onKeyPress ...' programmatically ? "Evertjan." <exjxw.hannivoort@interxnl.net> - 2012-01-18 22:55 +0000
    Re: How to set 'onKeyPress ...' programmatically ? "Mel Smith" <med_cutout_syntel@aol.com> - 2012-01-18 16:13 -0700
      Re: How to set 'onKeyPress ...' programmatically ? Tim Streater <timstreater@greenbee.net> - 2012-01-18 23:25 +0000
        Re: How to set 'onKeyPress ...' programmatically ? "Mel Smith" <med_cutout_syntel@aol.com> - 2012-01-18 16:31 -0700
      Re: How to set 'onKeyPress ...' programmatically ? "Evertjan." <exjxw.hannivoort@interxnl.net> - 2012-01-18 23:39 +0000
        Re: How to set 'onKeyPress ...' programmatically ? "Mel Smith" <med_cutout_syntel@aol.com> - 2012-01-18 16:53 -0700
  Re: How to set 'onKeyPress ...' programmatically ? "J.R." <groups_jr-1@yahoo.com.br> - 2012-01-18 23:26 -0200
  Re: How to set 'onKeyPress ...' programmatically ? Dr J R Stockton <reply1203@merlyn.demon.co.uk> - 2012-01-19 23:42 +0000
    Re: How to set 'onKeyPress ...' programmatically ? "Mel Smith" <med_cutout_syntel@aol.com> - 2012-01-19 17:07 -0700

csiph-web