www.webdeveloper.com
Results 1 to 2 of 2

Thread: onKeyPress event error

  1. #1
    Join Date
    Jul 2009
    Posts
    1

    onKeyPress event error

    I am having an error with firefox not wanting to accept an on key up event. I know that you have to program things differently for IE and FF but am having trouble doing so. Here is my working code in IE.

    there are several text fields that run this same function and some text fields that will not fun the function.

    Thanks in advance for any help.
    HTML Code:
              <input name="Lname" type="text"  class="input" id="nameinput" tabindex="2" value=""   onKeyDown="KeyCheck(form1)" />
    Code:
    function KeyCheck(frm)
    {
       var KeyID = event.keyCode;
       //alert(event.keyCode);
       switch(KeyID)
       {
    	   
            case 13:
            //document.Form1.cusLookup.currentValueIndices =1;
            frm.cusLookup.focus();
    	frm.cusLookup.options[1].selected = "1";     
    	//document.Form1.L.value = "Ctrl";
    	//
       }
    }

    This is the function i am trying to use but cant figure out how to call it from the html

    Code:
    function KeyCheck(e)
    {
      var KeyID = (window.event) ? event.keyCode : e.keyCode;
       switch(KeyID)
       {
           case 13:
          //document.Form1.cusLookup.currentValueIndices =1;
    	 frm.cusLookup.focus();
    	   frm.cusLookup.options[1].selected = "1";     
    		  //document.Form1.L.value = "Ctrl";
    	  //
       }
    }

  2. #2
    Join Date
    Oct 2003
    Location
    Andover, UK
    Posts
    945
    FF isn't quite as generous in the field of referencing events. IE lets you call the last event with event.[property] but with FF you need to pass the event physically to any function you want to reference it (or assign it to a function constant, e.g. myfuncname.myevent = evt, or a global variable) and reference it that way. Example:

    Code:
     if (!document.all) document.captureEvents(Event.MOUSECLICK);
    
    document.getElementById('someelement').onmouseclick = function() { dosomething(); }
    
    function dosomething() {
     dosomething.evt = evt; //from now on, the event can be references by calling dosomething.evt, from anywhere in your script
    }

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles