Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #10369 > unrolled thread
| Started by | "Mel Smith" <med_cutout_syntel@aol.com> |
|---|---|
| First post | 2012-01-18 15:47 -0700 |
| Last post | 2012-01-19 17:07 -0700 |
| Articles | 10 — 5 participants |
Back to article view | Back to comp.lang.javascript
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
| From | "Mel Smith" <med_cutout_syntel@aol.com> |
|---|---|
| Date | 2012-01-18 15:47 -0700 |
| Subject | How to set 'onKeyPress ...' programmatically ? |
| Message-ID | <9np0guFpjtU1@mid.individual.net> |
Hi: Enviro: >50 input text fields Question: How does one set _programmatically_ in javascript, the onKeyPress event listener ?? I tried a couple of statements (something like el.onKeyPress = myfunction() ; and "myfunction", etc, etc. Everything craps out and I don't know Where in my JavaScript Bible to look for the answer ?? A Hint please ?? Thank you -- Mel Smith
[toc] | [next] | [standalone]
| From | "Evertjan." <exjxw.hannivoort@interxnl.net> |
|---|---|
| Date | 2012-01-18 22:55 +0000 |
| Message-ID | <Xns9FDEF353B131Deejj99@194.109.133.133> |
| In reply to | #10369 |
Mel Smith wrote on 18 jan 2012 in comp.lang.javascript:
> Hi:
>
> Enviro: >50 input text fields
>
> Question: How does one set _programmatically_ in javascript, the
> onKeyPress event listener ??
>
> I tried a couple of statements (something like el.onKeyPress =
> myfunction() ; and "myfunction", etc, etc.
>
> Everything craps out and I don't know Where in my JavaScript Bible to
> look for the answer ??
>
> A Hint please ??
something like, [not tested]:
var inputs = document.forms[0].getElementsByTagName('input');
for (i=0;i<inputs.length;i++)
inputs[i].onKeyPress = myFunction;
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [next] | [standalone]
| From | "Mel Smith" <med_cutout_syntel@aol.com> |
|---|---|
| Date | 2012-01-18 16:13 -0700 |
| Message-ID | <9np21iF4v2U1@mid.individual.net> |
| In reply to | #10370 |
"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
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
} ;
}
}
*******************************
[toc] | [prev] | [next] | [standalone]
| From | Tim Streater <timstreater@greenbee.net> |
|---|---|
| Date | 2012-01-18 23:25 +0000 |
| Message-ID | <timstreater-FEC2D1.23251318012012@news.individual.net> |
| In reply to | #10371 |
In article <9np21iF4v2U1@mid.individual.net>,
"Mel Smith" <med_cutout_syntel@aol.com> wrote:
> ************* 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'
Well you've not added it yet, have you?
> // 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 :((
What do you mean by "craps out"?
> return true; // get out on 1st field for testing purposes. //
> I leave quickly while testing
> } ;
> }
> }
>
> *******************************
--
Tim
"That excessive bail ought not to be required, nor excessive fines imposed,
nor cruel and unusual punishments inflicted" -- Bill of Rights 1689
[toc] | [prev] | [next] | [standalone]
| From | "Mel Smith" <med_cutout_syntel@aol.com> |
|---|---|
| Date | 2012-01-18 16:31 -0700 |
| Message-ID | <9np31vFcp6U1@mid.individual.net> |
| In reply to | #10372 |
"Tim Streater" <timstreater@greenbee.net> wrote in message
news:timstreater-FEC2D1.23251318012012@news.individual.net...
> In article <9np21iF4v2U1@mid.individual.net>,
> Well you've not added it yet, have you?
>
>> // 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 :((
>
> What do you mean by "craps out"?
Hi Tim & Evertjan:
Yes, you are (of course) correct !
It occurred to me as I gave up in disgust, then returned a couple of
minutes ago, and tried it out with an alert *after* the assignment.
now, it returns 'function' as I wanted it to :))
Now,. can I pass an argument to the function (e.g.,
focusonElement(this) ).
Anyway, I'll try it tomorrow and see what happens
Thank you both very much !
-Mel Smith
[toc] | [prev] | [next] | [standalone]
| From | "Evertjan." <exjxw.hannivoort@interxnl.net> |
|---|---|
| Date | 2012-01-18 23:39 +0000 |
| Message-ID | <Xns9FDF6BFAC416eejj99@194.109.133.133> |
| In reply to | #10371 |
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)
[toc] | [prev] | [next] | [standalone]
| From | "Mel Smith" <med_cutout_syntel@aol.com> |
|---|---|
| Date | 2012-01-18 16:53 -0700 |
| Message-ID | <9np4ceFlgeU1@mid.individual.net> |
| In reply to | #10374 |
"Evertjan." <exjxw.hannivoort@interxnl.net> wrote in message
news:Xns9FDF6BFAC416eejj99@194.109.133.133...
> 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>
> ============================
Hi Evertjan:
Thanks for the code
Will try again tomorrow -- I have a granddaughter who has to be taken to
the airport in a few minutes.
-Mel
[toc] | [prev] | [next] | [standalone]
| From | "J.R." <groups_jr-1@yahoo.com.br> |
|---|---|
| Date | 2012-01-18 23:26 -0200 |
| Message-ID | <jf7rfs$eit$1@speranza.aioe.org> |
| In reply to | #10369 |
On 18/01/2012 20:47, Mel Smith wrote: > Hi: > > Enviro:>50 input text fields > > Question: How does one set _programmatically_ in javascript, the onKeyPress > event listener ?? > > I tried a couple of statements (something like el.onKeyPress = myfunction() > ; and "myfunction", etc, etc. > > Everything craps out and I don't know Where in my JavaScript Bible to look > for the answer ?? > > A Hint please ?? > > Thank you > Hi, You might use: el.onkeypress = myfunction; // neither onKeyPress nor myfunction() Take a look at MSDN to see more details: <http://msdn.microsoft.com/en-us/library/ms536939(v=vs.85).aspx> -- Joao Rodrigues (J.R.)
[toc] | [prev] | [next] | [standalone]
| From | Dr J R Stockton <reply1203@merlyn.demon.co.uk> |
|---|---|
| Date | 2012-01-19 23:42 +0000 |
| Message-ID | <pfvVOtedpKGPFwzD@invalid.uk.co.demon.merlyn.invalid> |
| In reply to | #10369 |
In comp.lang.javascript message <9np0guFpjtU1@mid.individual.net>, Wed,
18 Jan 2012 15:47:56, Mel Smith <med_cutout_syntel@aol.com> posted:
>Question: How does one set _programmatically_ in javascript, the onKeyPress
>event listener ??
PLUS : Just in case, and if you are testing in one browser and hoping to
run in all browsers, you should know about e & event in the following
working code; but I am not the one to actually explain it.
Rag.onmousedown = function (e) {
e = e || window.event
OldX = e.clientX ; OldY = e.clientY ; Doon = true }
--
(c) John Stockton, near London. *@merlyn.demon.co.uk/?.?.Stockton@physics.org
Web <http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, and links.
Correct <= 4-line sig. separator as above, a line precisely "-- " (RFC5536/7)
Do not Mail News to me. Before a reply, quote with ">" or "> " (RFC5536/7)
[toc] | [prev] | [next] | [standalone]
| From | "Mel Smith" <med_cutout_syntel@aol.com> |
|---|---|
| Date | 2012-01-19 17:07 -0700 |
| Message-ID | <9nrphoF5nfU1@mid.individual.net> |
| In reply to | #10413 |
DR. J said:
> Rag.onmousedown = function (e) {
> e = e || window.event
> OldX = e.clientX ; OldY = e.clientY ; Doon = true }
>
Hi Dr. Stockton:
My user (just one of them for now) is the office assistant who runs my
web app (which I'm building now) in the office of our senior park.
From gazing at my Apache access log, she currently runs IE9 , and
perhaps a slightly older IE from home -- which she doesn't use much. (We
are both used to communicating solely by email since I spend 7 months of the
year 3000 Km to the north)
Moving about the 50+ text fields (with only <Tab> and <Sh-Tab> will be
annoying to her. She is used to <CR>, and the Up/Down arrows to move around
a data entry screen. So, <Tab> and <Sh-Tab> are not real options for this
app
The web app is a Lot Management System (613 lots) with a home on the
lot, and owners, renters, lessors, as occupants, and maybe up to four local
(or remote) owners, and a lot of other contact infor on phones, email
addresses, full addresses (local and remote), etc, etc. Then, there's the
non-owner occupancy fee, and how it is collected and reported uipon, etc.
... Now, I'm scaring the Hell out of myself :(
But anyway, I understand that events are treated differently among the
browsers, and I'll be searching in my "Javascript Bible" for guidance.
But, I don't understand your code above, and its late in the day, and
I'm tired out from golfing : (((
Thanks for the post !
-Mel
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.javascript
csiph-web