473,408 Members | 1,734 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

detecting ENTER

mk
Hi

I'v got the following javascript (part of it) that works with the event
onmouseup:

// Attach event handlers to all images within container
LICollection=document.getElementById("MDME").getEl ementsByTagName("LI");
if (LICollection!=null)
{ for (l=0; l<LICollection.length; l++)
{LICollection.item(l).onmouseup=onMouseUpHandler;}
}

Now I modified it so it works with onkeydown:

// Attach event handlers to all images within container
LICollection=document.getElementById("MDME").getEl ementsByTagName("LI");
if (LICollection!=null)
{ for (l=0; l<LICollection.length; l++)
{LICollection.item(l).onmouseup=onMouseUpHandler;
LICollection.item(l).onkeydown=onMouseUpHandler;}
}

This works fine, but actually I want only that it works whit ENTER
pressed. When I try this:

// Attach event handlers to all images within container
LICollection=document.getElementById("MDME").getEl ementsByTagName("LI");
if (LICollection!=null)
{ for (l=0; l<LICollection.length; l++)
{LICollection.item(l).onmouseup=onMouseUpHandler;
LICollection.item(l).onkeydown(Key.ENTER)=onMouseU pHandler;}
}

nothing happens anymore?

Any clue for me?
Thanks ajavascript newbee.
Markus

Sep 25 '06 #1
3 1537
mk wrote:

Hi,
This works fine, but actually I want only that it works whit ENTER
pressed. When I try this:
LICollection.item(l).onkeydown(Key.ENTER)=onMouseU pHandler;}
With this syntax, it's like you'd consider the onkeydown property of the
LI element to be a callable object :) It's not, then rather define and
use the following.
---
function onKeyDownHandler(evt) {
if((evt||event).keyCode==13)
onMouseUpHandler.call(this,evt);
}
---
Regards.
Sep 25 '06 #2
Elegie wrote:
mk wrote:
>This works fine, but actually I want only that it works whit ENTER
pressed. When I try this:
>LICollection.item(l).onkeydown(Key.ENTER)=onMouse UpHandler;}

With this syntax, it's like you'd consider the onkeydown property of the
LI element to be a callable object :) It's not,
It might be. Once the element has been assigned an onkeydown handler it
certainly would be callable. That doesn't help at all as - key.Enter -
is a meaningless argument and you cannot assign to the return value
from a function call anyway.
then rather define and
use the following.
---
function onKeyDownHandler(evt) {
if((evt||event).keyCode==13)
onMouseUpHandler.call(this,evt);
As the element has had an onmouseup handler assigned there is no need
to use the - call - method, as calling that handler directly and
passing the - evt - argument in will sufficiently simulate the mouse
event (and get the - this - reference right):-

this.onmouseup(evt);

Richard.

Sep 25 '06 #3
Richard Cornford wrote:
>With this syntax, it's like you'd consider the onkeydown property of the
LI element to be a callable object :) It's not,
It might be. Once the element has been assigned an onkeydown handler it
certainly would be callable. That doesn't help at all as - key.Enter -
is a meaningless argument and you cannot assign to the return value
from a function call anyway.
Don't hit too hard, I know I've been weak there :) I didn't want to say
anything in the first place about the construct, and still wanted to
provide the OP with a basic explanation - so I ended in writing, out of
laziness, quite an inappropriate comment :$

>function onKeyDownHandler(evt) {
if((evt||event).keyCode==13)
onMouseUpHandler.call(this,evt);

As the element has had an onmouseup handler assigned there is no need
to use the - call - method, as calling that handler directly and
passing the - evt - argument in will sufficiently simulate the mouse
event (and get the - this - reference right):-

this.onmouseup(evt);
Yes this is definitely possible, and will indeed avoid the use of 'call'
(which wasn't supported in ancient browsers). However, I have a bad
feeling each time I see such statements, because it generally means the
event-management layer is simplistic. My proposal of course does not
make anything better, however it does express, by its form, that it is
merely a patch to a deeper problem :)
Regards,
Elegie.
Sep 25 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: MDW | last post by:
Say I've got a page - myPage.asp - that expects to see the results of a form's POST operation. If it comes from the form, all is fine. However, if someone were to manually type the address in...
3
by: RM Powell | last post by:
OK, this is probably a dumb, newbie quesiton. But I've searched quite a bit on this group and in the "help" files and haven't been able to find the answer. I run a crisis program for kids and...
2
by: Randy | last post by:
I have a DataTable in a DataGrid on a Windows form. I have comboboxes in the first column, and that seems to work just fine. The second column is for a money amount. The numeric dollar value...
1
by: Simon Harvey | last post by:
I'm having a problem with a textbox I'm using. On all the other pages i have, if the user presses the enter key the form submits and moves on to the next page. However with this page if the user...
2
by: Sam-Kiwi | last post by:
I've spent the last 6 months developing a pay-per-download website using ASP.NET Users purchase documents and then download them. The intention is that users are only charged for documents...
4
by: david.w.anderson1 | last post by:
This is a homework assignment. The code works but does not "catch" all the improper input. The requirement is to be able to accept one input currency, which is error checked as a valid entry, and...
4
by: almurph | last post by:
Hi everyone, I'm a newbie to javascript. I have written some code to detect when a user presses the down-arrow, up-arrow and enter button. Essentially the user can arrow down or up through a...
3
by: prashantdwivedi | last post by:
i want to write a program that display data type of enterd value that enter by user.E.G. if user enter 2 then our program will display it is an integer value,if user enter 10.5 then our program will...
2
by: newbiegalore | last post by:
Hello everyone I have just finished going through some tutorials on developing extensions for mozilla and have made a version of the born-geek toolbar. Being a newbie I am stuck at a relatively...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.