Hello, I have a problem with the Event.observe method on IE. When I use The Event.observe method, the key code that I retrieve from the event, is different if I use an inline function. Here is the html code to test it (You must have prototype.js on the same directory) <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title> Example </title> <script src="prototype.js" type="text/javascript"></script> <script language="javascript" type="text/javascript"> //browser detection function maskKeyPress(objEvent) { var iKeyCode, strKey; var strUserAgent = navigator.userAgent.toLowerCase(); var isIE = strUserAgent.indexOf("msie") > -1; if (isIE) { iKeyCode = objEvent.keyCode; } else { iKeyCode = objEvent.which; } strKey = String.fromCharCode(iKeyCode); alert("KeyCode = " + iKeyCode + "\nCharacter =" + strKey); } window.onload = function () { var field = document.forms[0].name1; Event.observe(field, "keypress", maskKeyPress, true ); } </script> <style type="text/css"> body, p, td { font-family: Verdana, Arial, Helvetica; font-size: 9pt; } </style> </head> <body> <h1>Example</h1> <p>For this example, try typing one of these characters ($,*,%,...) into the 2 textboxes below. You will see an alert that displays the character and the keycode corresponding to the key you pressed. And the keyCode is different when using Event.observe</p> <form name="tempForm" action="#"> <p><input type="text" name="name1" size="20"></p> <p><input type="text" name="name2" onkeypress="maskKeyPress(window.event);" size="20"></p> </form> </body> </html> Have someone a idea of how to make it work?... Thank you in advance. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
On Jun 7, 8:05 pm, John <ichae...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hello, > > I have a problem with the Event.observe method on IE. > When I use The Event.observe method, the key code that I retrieve from > the event, > is different if I use an inline function. > > Here is the html code to test it (You must have prototype.js on the > same directory)Dunno about the IE issue since I don''t have it available right now, however... [...]> //browser detection > > function maskKeyPress(objEvent) { > var iKeyCode, strKey; > > var strUserAgent = navigator.userAgent.toLowerCase(); > var isIE = strUserAgent.indexOf("msie") > -1; > if (isIE) { > iKeyCode = objEvent.keyCode; > } else { > iKeyCode = objEvent.which; > }Browser detection is a really bad idea, instead consider: var iKeyCode = objEvent.keyCode || objEvent.which; -- Rob --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
...and as for the problem you''re having. Yep, ''tis a very annoying problem. Can you clarify, though, when the keycode is different? Is it always different, or only for capital letters? Because my problem with this was related to getting the same keycode for a letter, regardless of typing a capital letter or not. They want you to check the modifiers to see if the shift key was also depressed and deduce on your own whether or not it should be capital (which of course doesn''t take in to account whether or not the capslock key is on). Anyway... the answer, unfortunately, is to not use Event.observe, but attach the handler directly like this (thus bypass the new W3C event model)... field.onkeypress = maskKeyPress; The above is the same result as attaching the handler inline. This is certainly not an ideal thing to do, but, it does work. On 6/7/07, RobG <rgqld-AFFH1GffN5hPR4JQBCEnsQ@public.gmane.org> wrote:> > > > > On Jun 7, 8:05 pm, John <ichae...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Hello, > > > > I have a problem with the Event.observe method on IE. > > When I use The Event.observe method, the key code that I retrieve from > > the event, > > is different if I use an inline function. > > > > Here is the html code to test it (You must have prototype.js on the > > same directory) > > Dunno about the IE issue since I don''t have it available right now, > however... > > [...] > > //browser detection > > > > function maskKeyPress(objEvent) { > > var iKeyCode, strKey; > > > > var strUserAgent > navigator.userAgent.toLowerCase(); > > var isIE = strUserAgent.indexOf("msie") > > -1; > > if (isIE) { > > iKeyCode = objEvent.keyCode; > > } else { > > iKeyCode = objEvent.which; > > } > > Browser detection is a really bad idea, instead consider: > > var iKeyCode = objEvent.keyCode || objEvent.which; > > > -- > Rob > > > > >-- Ryan Gahl Principal, Manager Nth Penguin, LLC - Consulting http://www.nthpenguin.com -- Software Architect WebWidgetry.com / MashupStudio.com Future Home of the World''s First Complete Web Platform -- Inquire: 1-262-951-6727 Blog: http://www.someElement.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Hi, Thank you for the browser detection tips, Rob ;-) Ryan, thanks for your help. In fact, I was using a french keyboard (You would probably ask why. It''s simply because I am one ;-) And in the french keyboard, there are more characters and the non standard ASCII characters are not well managed by the Event.connect method. Just for information, I have tested with dojo (dojo.event.connect), just to try and it works.... Thank you for your comments. Bye.... On Jun 7, 3:51 pm, "Ryan Gahl" <ryan.g...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> ...and as for the problem you''re having. Yep, ''tis a very annoying problem. > Can you clarify, though, when the keycode is different? Is it always > different, or only for capital letters? Because my problem with this was > related to getting the same keycode for a letter, regardless of typing a > capital letter or not. They want you to check the modifiers to see if the > shift key was also depressed and deduce on your own whether or not it should > be capital (which of course doesn''t take in to account whether or not the > capslock key is on). Anyway... the answer, unfortunately, is to not use > Event.observe, but attach the handler directly like this (thus bypass the > new W3C event model)... > > field.onkeypress = maskKeyPress; > > The above is the same result as attaching the handler inline. > > This is certainly not an ideal thing to do, but, it does work. > > On 6/7/07, RobG <r...-AFFH1GffN5hPR4JQBCEnsQ@public.gmane.org> wrote: > > > > > > > On Jun 7, 8:05 pm, John <ichae...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Hello, > > > > I have a problem with the Event.observe method on IE. > > > When I use The Event.observe method, the key code that I retrieve from > > > the event, > > > is different if I use an inline function. > > > > Here is the html code to test it (You must have prototype.js on the > > > same directory) > > > Dunno about the IE issue since I don''t have it available right now, > > however... > > > [...] > > > //browser detection > > > > function maskKeyPress(objEvent) { > > > var iKeyCode, strKey; > > > > var strUserAgent > > navigator.userAgent.toLowerCase(); > > > var isIE = strUserAgent.indexOf("msie") > > > -1; > > > if (isIE) { > > > iKeyCode = objEvent.keyCode; > > > } else { > > > iKeyCode = objEvent.which; > > > } > > > Browser detection is a really bad idea, instead consider: > > > var iKeyCode = objEvent.keyCode || objEvent.which; > > > -- > > Rob > > -- > Ryan Gahl > Principal, Manager > Nth Penguin, LLC - Consultinghttp://www.nthpenguin.com > -- > Software Architect > WebWidgetry.com / MashupStudio.com > Future Home of the World''s First Complete Web Platform > -- > Inquire: 1-262-951-6727 > Blog:http://www.someElement.com--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---