Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: "Mel Smith" Newsgroups: comp.lang.javascript Subject: Re: How to set 'onKeyPress ...' programmatically ? Date: Wed, 18 Jan 2012 16:13:50 -0700 Lines: 46 Message-ID: <9np21iF4v2U1@mid.individual.net> References: <9np0guFpjtU1@mid.individual.net> X-Trace: individual.net UnK9aeZTFEOfGYztigRq5QWroYUTSo4sqmhmiQzGxKm5+OWopR Cancel-Lock: sha1:PWVMldn3Y2wHgx5AePDviQS0dcs= X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5931 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.6157 X-RFC2646: Format=Flowed; Original Xref: x330-a1.tempe.blueboxinc.net comp.lang.javascript:10371 "Evertjan." 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[i].onKeyPress = myFunction; Hi Evertjan: Here is what I started with below It still shows undefined for el.onKeyPress. Any more guidance please ? Thank you for responding. -Mel Smith ************* my original code ******* function setonpress() { var el ; var inputs = document.getElementsByTagName("input") ; // now we have to add a keypress function to each of them for (var i=0;i<=inputs.length;i++) { el = inputs[i] ; if (el.type === "text") { window.alert("type of el.onKeyPress = "+ typeof el.onKeyPress) ; // always results in 'undefined' // I wish the focusOnElement function to be 'planted' in each of my 50+ text fields // and I don't what to have to type them in. el.onKeyPress = focusOnElement ; // so this craps out :(( return true; // get out on 1st field for testing purposes. // I leave quickly while testing } ; } } *******************************