PDA

View Full Version : How to replace "click button" by "press key"


pegasus3009
07-03-2008, 10:42 AM
I have 4 forms in a PHP page, I want when an user press arrow key on keyboard: up,left,right,down. The browser will run every forms as below (no need click button as normal):

Up: ==>
<FORM action=$base_url/......&act=move&move=up method=post><input type=submit name=Submit VALUE="Move Up"></form>

Left ==>
<FORM action=$base_url/......&act=move&move=left method=post><input type=submit name=Submit VALUE="Move Left"></form>

Right ==>
<FORM action=$base_url/......&act=move&move=right method=post><input type=submit name=Submit VALUE="Move Right"></form>

Down ==>
<FORM action=$base_url/......&act=move&move=down method=post><input type=submit name=Submit VALUE="Move Down"></form>


I think we will use javascript.
Thanks you.

pegasus3009
07-03-2008, 11:10 AM
<script language="javascript" type="text/javascript">
<!--
document.onkeydown = function keyPress(evt)
{
var keyCode =
document.layers ? evt.which :
document.all ? event.keyCode :
document.getElementById ? evt.keyCode : 0;
if (keyCode == 37)
{__doPostBack(document.location="http://www.URL1.com",'')}
if (keyCode == 38)
{__doPostBack(document.location="http://www.URL2.com",'')}
if (keyCode == 39)
{__doPostBack(document.location="http://www.URL3.com",'')}
if (keyCode == 40)
{__doPostBack(document.location="http://www.URL4.com",'')}


}
//-->
</script>

I fould it, but it's only work with IE, how to do with Firefox?

Fou-Lu
07-03-2008, 05:00 PM
Since you are using javascript, you will likely get a better response from the JS forum. I'm guessing you'll need to actually submit the form with a form.submit, but js is by no means my expertise.