FRIHOSTFORUMSSEARCHFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

key press

 


sonam
I have links what with ajax and php change images in a gallery. Links are looking like this one:

Code:
<a href="javascript:void(0)" onClick="loadurl('galerija/prevnext.php?current=$next'), HideContent('gi'); return true " >NEXT</a>


This is working perfect but I would like to include one additional option. I would like if someone click on left or right arrow on tastature to get the same result - changing the image. Is it possible to include some javascript in this existing link. Any sugestion is welcome.

Sonam
brokenadvice
No. The way you have it, the JavaScript will only activate when you click on the link. You will have to add something like this:

Code:

<html>
<head>
<title>Capturing Aarow presses</title>

<script type="text/JavaScript">

function doKey($key) {
if ($key == 39) {
   window.location = 'prevnext.php?current=$next';
   } else {
      if ($key == 37) {
         window.location = 'prevnext.php?current=$prev';
      }
   }
}
</script>

</head>

<body onKeyDown="doKey(window.event.keyCode)">



</body>
</html>
sonam
brokenadvice wrote:
No. The way you have it, the JavaScript will only activate when you click on the link. You will have to add something like this:

Code:

<html>
<head>
<title>Capturing Aarow presses</title>

<script type="text/JavaScript">

function doKey($key) {
if ($key == 39) {
   window.location = 'prevnext.php?current=$next';
   } else {
      if ($key == 37) {
         window.location = 'prevnext.php?current=$prev';
      }
   }
}
</script>

</head>

<body onKeyDown="doKey(window.event.keyCode)">



</body>
</html>


I didn't try your sugestion but I will. What do you mean can I use loadurl instead of window.location because I need to call ajax not new window. But sorry if I ask stupid question but I don't know too much about Javascript.

Sonam
brokenadvice
Well, I only know little about AJAX. I didn't know what loadurl was, so I went with what I knew. If loadurl is just a function you can replace:

Code:
window.location = 'prevnext.php?current=$next';


with

Code:
loadurl('galerija/prevnext.php?current=$next'), HideContent('gi'); return true;


and likewise for the other arrow.
Marcuzzo
Code:
<html>
<head>
<title>CrossBrowser Example</title>
<script type="text/JavaScript">
window.onload=function(){
  document.onkeydown = function(e){
    var evt = (e) ? e : window.event;
   switch ( evt.keyCode){
    case 39 :
      loadurl('galerija/prevnext.php?current=$next');
      HideContent('gi');
      return true;
      break;
    case 37 :
      loadurl('galerija/prevnext.php?current=$prev');
      HideContent('gi');
      return true;
      break;
   }
  }
}
</script>
</head>
<body>
</body>
</html>
sonam
Thanks for yours help but I cannot find good solution. Ajax don't or wrong recognise my input. I don't know why but I think how $next and $prev don't send right number. Is it possible to put this script somewhere in body instead of head because ajax just call simple php and display images in one div.

Sonam
Related topics

Microsoft blows it again... (Why NOT to use IE)
Pixels
mobile programmers codes
Windows XP Tricks & Tips!!!!
OCD (Obsessive Compulsive Disorder)

Simple menu written in C - Problem with loop
Adobe Photoshop
SHORTCUT KEY
Avoid Accidental Caps Lock Key Hitting
10 Greatest inventions...

new Nintendo Revolution
Strange Fire fox problem
Can games grow beyond the hard-core set?
Alot of funny pics...!
Windows Tips&tricks!
Reply to topic    Frihost Forum Index -> Scripting -> Html, CSS and Javascript

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.