Jump to content

[SOLVED] Javascript, change page on key press.


MadnessRed

Recommended Posts

What I would like to do is to be able let the user change page by using JavaScript and the left/right key arrows. I want to make this JavaScript as simple as possible so that I can understand it as I am not very good with JavaScript.

 

I have tried searching Google but what i have found does seem to work for me.

 

Here is what I have atm.

 

<table cellpadding="0" cellspacing="0" border="0" onkeydown="Javascript: calckeys();">/code]

That is in the body.

Now, I also have, (in the body also but at the top of the page)

[code]<script language="JavaScript">
function calckeys() {
	if (!e) e=window.event;
	switch(e.keyCode){
	case 37:
		// Key left.
		mr_submit('Left');
		break;
	case 38:
		// Key up.
		mr_submit('Up');
		break;
	case 39:
		// Key right.
		mr_submit('Right');
		break;
	case 40:
		// Key down.
		mr_submit('Down');
		break;
	}
}

</script>

 

 

Can anyone please help me to get this script working,

 

many thanks

 

Anthony,

 

(the Up, Down,Left and Right functions work fine in the following situations

 

<img src="left.png" onclick"Javascript: Left();" />

 

 

 

Edit: found a script to use Ctrl-S to save, and edited my scripts, now it works.

 

 

<script language="JavaScript">
document.onkeydown=function(e){
	switch(e.which){
	case 37:
		// Key left.
		mr_submit('Left');
		break;
	case 38:
		// Key up.
		mr_submit('Up');
		break;
	case 39:
		// Key right.
		mr_submit('Right');
		break;
	case 40:
		// Key down.
		mr_submit('Down');
		break;
	}
}

</script>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.