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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.