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 [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to