473,322 Members | 1,307 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,322 software developers and data experts.

Cross browser attach event function and firefox events

Hi,
I am trying to work out how to access the event object in firefox
under two conditions -
1) Attaching event handlers in javascript, not html.
2) The event handler requires parameters in addition to the event
object.

Here is an HTML page that demonstrates the problem. Notice that it
works in IE but not firefox.

Expand|Select|Wrap|Line Numbers
  1.  
  2. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/
  3. TR/html4/strict.dtd">
  4. <html>
  5. <head>
  6. <title>My page</title>
  7. <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  8. </head>
  9. <body>
  10.  
  11. <form action="">
  12.  
  13. <p><input id="testBox" type="text" /></p>
  14.  
  15. </form>
  16.  
  17. <script type="text/javascript">
  18.  
  19. function XBrowserAddHandler(target,eventName,handlerName)
  20. {
  21. if ( target.addEventListener )
  22. target.addEventListener(eventName, handlerName, false);
  23. else if ( target.attachEvent )
  24. target.attachEvent("on" + eventName, handlerName);
  25. else
  26. target["on" + eventName] = handlerName;
  27. }
  28.  
  29. var y = 3;
  30.  
  31. var txtTestBox = document.getElementById('testBox');
  32.  
  33. XBrowserAddHandler(txtTestBox, 'keyup', function()
  34. { myFunctionRef(y) });
  35.  
  36. var myFunctionRef = function myFunction(x, e)
  37. {
  38. var keyCode;
  39.  
  40. if (!e && window.event)
  41. e = window.event;
  42.  
  43. if (e)
  44. keyCode = (window.Event) ? e.which : e.keyCode;
  45.  
  46. alert('You pressed: ' + keyCode + '. Event object is :' + e + '. x
  47. is: ' + x);
  48. }
  49. </script>
  50.  
  51. </body>
  52. </html>
  53.  
  54.  
Mar 2 '07 #1
1 15635
On Mar 2, 4:39 pm, "acl123" <andrewclawre...@gmail.comwrote:
Hi,
I am trying to work out how to access the event object in firefox
under two conditions -
1) Attaching event handlers in javascript, not html.
2) The event handler requires parameters in addition to the event
object.
Some reading:

<URL: http://www.quirksmode.org/js/introevents.html >
--
Rob

Mar 2 '07 #2

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

Similar topics

68
by: Steve | last post by:
Hi There, Prob a simple answer to this (I hope) but I can't quite work it out yet... I have this in a page: <map name="Map"> <area shape="rect" coords="43,68,52,77" href="map.html"...
4
by: John Fereira | last post by:
So, one of the limitations of multipart-form handling is that when an <input type="file" ..> tag is used it will bring up a window which allows a user to select a file for upload but won't allow...
1
by: cjl | last post by:
Hey all: I'm trying to write a cross-browser (IE and firefox) event handler for the mousewheel. Basically my web app is an image viewer, so if you scroll "down" with the wheel the next image...
2
by: Eric Caron | last post by:
Hi everybody, I was doing some cross-browser tests today and I found out that if you specify the width and height for a button type control, asp.net doesn't output the style information when...
7
by: dwandless | last post by:
I have successfully installed a BHO in IE7. Using C#. Now I'm trying to figure out how to trap various events. onkeypress, oncut, oncontextmenu, etc. I have tried calling in various...
1
by: Rancid Buttchutney | last post by:
I've tried searching the web but I've had little success finding a cross-browser(IE, Firefox and Opera anyway) implementation of a restricted text INPUT that works in realtime before a character...
7
by: =?iso-8859-1?q?Jesper_R=F8nn-Jensen?= | last post by:
Hi. I just ran into a situation where I want to emulate the IE specific obj.click() syntax on an object on the webpage. The most convenient thing for me is if I were able to just select my ...
2
by: mattgarvin | last post by:
Hello, I need a piece of javascript that will allow a form to be submitted when Enter is pressed for IE6 and 7, Firefox 2, and recent versions of Safari. It is for a login page that has two...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.