473,698 Members | 2,522 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

dynamically add onmousemove function with event as attribute

hsriat
1,654 Recognized Expert Top Contributor
<body onmousemove="mo veMe()">

This function can also be called as
document.onmous emove = function {moveMe();};

Similarly what can be done for onmousemove="mo veMe(event)" ?
May 24 '08 #1
15 2311
Jezternz
145 New Member
I am interested in the answer to this also, I recently had the same issue. I just took a shortcut by storeing the "event" in a global variable, but if theres another way I would like to know.
Thanks, Josh
May 24 '08 #2
gits
5,390 Recognized Expert Moderator Expert
i think you mean something like the following?

Expand|Select|Wrap|Line Numbers
  1. function my_event(e) {
  2.     alert('test ' + e.target.tagName);
  3. }
  4.  
  5. window.document.onclick = function(event) {
  6.     return function(event) { my_event(event) };
  7. }();
you should always avoid the assignment as a string since this is eval-like and never needed, even in the setTimeout and setInterval methods. but the best way would be to use attachEvent() for IE and addEventListene r() for the other browsers ... when it comes to event-handling.

note: the example works in FF/Mozilla - IE has no target, but you may use srcElement here ... ;)

kind regards
May 25 '08 #3
hsriat
1,654 Recognized Expert Top Contributor
Thank you Gits.

May 25 '08 #4
gits
5,390 Recognized Expert Moderator Expert
no problem ... i just hate that eval and eval-like things ... since it is not needed as i said and makes the code quite ugly :) there are needs for it (when JSON is to be evaled) but even that might be obsolete in the future ... have a look here in case you are interested :)

kind regards
May 25 '08 #5
hsriat
1,654 Recognized Expert Top Contributor
Did not work on ie.. :(
May 26 '08 #6
acoder
16,027 Recognized Expert Moderator MVP
Don't forget that IE uses the global window.event. Use something like this to get the target.
May 26 '08 #7
hsriat
1,654 Recognized Expert Top Contributor
Don't forget that IE uses the global window.event. Use something like this to get the target.
Thanks, so it finally worked like this..
Expand|Select|Wrap|Line Numbers
  1.     document.onmousemove = function (event) {
  2.     if (!event) event = window.event;
  3.     drag(event);
  4. };
May 26 '08 #8
acoder
16,027 Recognized Expert Moderator MVP
Yes, and another alternative:
Expand|Select|Wrap|Line Numbers
  1. event = event || window.event;
May 26 '08 #9
hsriat
1,654 Recognized Expert Top Contributor
Thats better, will use this one ...
Expand|Select|Wrap|Line Numbers
  1. drag(event || window.event);
May 26 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

4
12573
by: Eric | last post by:
How can I dynamically assign an event to an element? I have tried : (myelement is a text input) document.getElementById('myelement').onKeyUp = "myfnc(param1,param2,param3)"; document.getElementById('myelement') = new Function("myfnc(param1,param2,param3)");
2
2779
by: Mariusz | last post by:
Hello, I'm trying to do drag'n'drop where You can see elements that You are dragging (table rows exactly) but I have small problem. Here is code sample var move = false; function onDragStart(id) { move = true; return true; }
2
18575
by: RobG | last post by:
I am trying to dynamically add an onclick to an element, however I just can't get the syntax right. consider the following function: function doClick (evt,x) { // do things with evt and x } Which is called statically by: <button onclick="doClick(event,this);">Click me</button>
6
3323
by: Thomas | last post by:
Hi, I'm having a problem with the dynamically created inputfields in Internet Explorer. The situation is the following: - I have a dynamically created table with a textbox in each Cell. - It is possible to Add and Delete rows - Some cells have special attributes (readonly and events) Here's a snippet of the code:
20
12884
by: David | last post by:
I have a one-line script to add an onunload event handler to the body of the document. The script is as follows: document.getElementsByTagName("BODY").onunload=function s() {alert("s")} Now obviously, I put the alert("s") part in for debugging purposes, just to make sure the error wasn't in any code I was going to be running. This line works just fine in IE6 but in Firefox it doesn't. However, if I replace that line with the...
5
5510
by: Ravi | last post by:
In IE (tested IE6 on W2k&WXP) onmousemove event appears to fire continually when mouse is over the document and not moving or touched at all, even when mouse is physically detached from the computer. Same page on Firefox works well (event fires only when mouse moves, not when it is static on the document). Seems a bug, doesn't it? Anyone knows something about this or a solution?
1
4497
by: k.roemke | last post by:
Hello! After a longer time I want to do some javascript again. Task: set content of an iframe to the origin page if the mouse is not moved Problem: <iframe onmousemove="resetCounter();return true;" does not work as expected.
7
1952
by: CpVermont | last post by:
I've created a window management object for my ajax pages. It opens windows and attaches them to the DOM element specified and then keeps track of them and removes them from DOM when the user closes them. I'm trying to add drag and drop. I am able to assign the mouse event handlers to them, but unable to send the event to the function. // This is assigned to the parent of the window that has been selected to move...
0
8608
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9029
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8898
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7734
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6524
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3051
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2006
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.