SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: keycode problem

Hybrid View

  1. #1
    SitePoint Evangelist Jedi007's Avatar
    Join Date
    Aug 2005
    Posts
    463
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    keycode problem

    While the uuser is focused on a textbox, I want him to be able to press enter and run a certain function. Function calls from onkeydown in the text area work fine but this script doesn't seem to work. Here's what I have (basically ripped it off of w3schools)

    I have absolutely no idea what's going on

    Code:
    function checkit()
    	{
    	var keynum
    	var keychar
    	if(window.event) // IE
    			{
    			keynum = e.keyCode
    			}
    		else if(e.which) // Netscape/Firefox/Opera
    			{
    			keynum = e.which
    			}
    	keychar = String.fromCharCode(keynum)
    	document.write(keychar);
    	}

  2. #2
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Alter your code to alert the keynum after you obtain it. Then hit the enter key and note which key code is displayed for keynum. Then go back and alter your code so that if the keynum is equal to the key code you observed for the enter key, you call the function.

  3. #3
    SitePoint Evangelist Jedi007's Avatar
    Join Date
    Aug 2005
    Posts
    463
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tried that

    Code:
    function checkit()
    	{
    	var keynum
    		else if(e.which) // Netscape/Firefox/Opera
    			{
    			keynum = e.which
    			}
    	alert("1");
    	}
    doesn't work so alerting keynum for sure wont work. but when I replace the function with:

    Code:
    function checkit()
    	{
    	alert("1");
    	}
    it works.. ?


Bookmarks

Posting Permissions

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