views:

41

answers:

5
+2  Q: 

Keyboard events

A: 

I don't know how to do this w/ jQuery [but i'm sure it'll be very simple].

In terms of pure javascript, you can get the link's reference using document.getElementById. Then retrieve its href attribute using .href. Lastly, change the document's location to the href location -> document.location = href

if you don't want a redirection, then set the form's action attribute and do form.submit()

anirvan
+1  A: 

You could try

$(document).bind("keydown", function(e) {
  if (e.ctrlKey) {
    if(e.keyCode == 37) {
        document.getElementById("prevButton").click();
    }
    else if(e.keyCode == 39) {
        document.getElementById("nextButton").click();
    }
  }
});

code 37 is for left arrow & code 39 for right arrow

rohk
+1  A: 

You may want to look into using a library called jquery.hotkeys, found here: http://github.com/tzuryby/jquery.hotkeys . If not using the library itself, the source code can give you an idea of what needs to be done.

[Disclaimer: I found this library via searching, and have not used it nor tested it myself. Use at your own discretion.]

Dan D.
+3  A: 
$(document).keydown(function(e) {
  if(e.ctrlKey){
     if(e.keyCode == 37){
        //ctrl + leftbutton pressed
        $("a.prevButton").trigger("click");
     }else if(e.keyCode == 39){
        //ctrl + rightbutton pressed
        $("a.nextButton").trigger("click");
     }
  }
});

fiddle it live

red-X
this + `$('#previous').trigger('click');` (if the previous link got `id="previous"` of course)
Chouchenos
what is keyCode = 37/39? Where can I find all the key codes?
Happy
http://www.cambiaresearch.com/c4/702b8cd1-e5b0-42e6-83ac-25f0306e3e25/Javascript-Char-Codes-Key-Codes.aspx is what your looking for
red-X
+1  A: 

just use this plugin with jQuery and you can set up key combinations for shortcuts: http://plugins.jquery.com/project/hotkeys.

you can set up shortcuts like this:

<script type="text/javascript">
        $(document).ready(function(){
            shortcut("Ctrl+Right",function() {
            document.getElementById("your next button ID").click();
        });
        shortcut("Ctrl+Left",function() {
        document.getElementById("your prev button ID").click();
        });
    });
</script>
Ervin