0

I am working on a site that displays images and forms from a database. Currently, I have links disguised as buttons that allows the user to switch to previous and next files.

$prev_key=$filenum.'_'.($fileindex-1);
$next_key=$filenum.'_'.($fileindex+1);

if(($fileindex-1)>=1)
  echo '<br>';
  echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="view_file.php?k='.$prev_key.'" class="prevnext">Prev File</a>';  

if(($fileindex+1)<=$totalfilect)
  echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="view_file.php?k='.$next_key.'" class="prevnext">Next File</a>';

This works well, but I also want the user to be able to switch files using the up (previous) and down (next) arrow keys. How could I either call the $prev_key and $next_key functions or have the key presses just activate the links with key presses?

Hunter Turner
  • 6,804
  • 11
  • 41
  • 56
MisterDave
  • 11
  • 3

1 Answers1

0

You have to make use of JavaScript-EventListener onKeyPress or onKeyUp - depending on your preferences or customer requirements. http://www.w3schools.com/jsref/event_onkeyup.asp

In the JS-EventListener code you have to call the respective url then. This is described in an other StackOverflow entry: https://stackoverflow.com/a/980721/3904215

Community
  • 1
  • 1
Alexander
  • 501
  • 1
  • 6
  • 16