Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

onkeypress will change the style class but changes back.

Status
Not open for further replies.

milo3169

Programmer
May 2, 2007
42
0
0
Hello everyone,

I am working on a AJAX autocomplete script and the autocomplete is working, but I would like to add some more functionality to by adding navigation through the list with the UP and DOWN arrow keys. I seem to have the javascript working where when I press down one of the arrow keys it seems to change the className, but it immediately will change the className back to the original className. Would anybody be able to tell me why this is happening? What am I doing wrong?

Code:
document.onkeypress = KeyCheck;

 var HighlightSelection = -1;
	function KeyCheck(e){
		   var KeyID = (window.event) ? event.keyCode : e.keyCode;
 
		switch(KeyID){
 
			case 38:
		    HighlightSelection--;
			setHighlightSelection(HighlightSelection);	
		    break;
			
			case 40:
			HighlightSelection++;
			setHighlightSelection(HighlightSelection);
			break;
 
		}
	}
	
function setHighlightSelection(num){
	document.getElementById(num).className = "suggest_link_over";
}
I know that the function "setHighlightSelection" is very basic, but it's being used for testing purposes.

Thank you in advance.
milamsteve
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top