-2

I am trying to scroll down the page using javascript.

I have this code which works fine if if i use javascript:pageScroll() in a link or button:

<SCRIPT LANGUAGE="Javascript">
function pageScroll() {
        window.scrollBy(0,50); // horizontal and vertical scroll increments
        scrolldelay = setTimeout('pageScroll()',100); // scrolls every 100 milliseconds
}
</SCRIPT>

but i need to find out how i can call the pageScroll() function if the user presses enter on their keyboard?

any help would be greatly appreciated.

Simon Presto
  • 167
  • 3
  • 5
  • 14
  • add an `onkeydown` event? I really am not sure what you are asking, did you try anything? – Naftali Aug 12 '13 at 14:32
  • http://stackoverflow.com/questions/905222/enter-key-press-event-in-javascript - stackoverflow is not supposed to be a google replacement? – matpol Aug 12 '13 at 14:34

2 Answers2

8
$(document).keypress(function(e) {
    if(e.which == 13) {
        //do stuff
    }
});
0

Use jQuery, you might be interested in .keypress(). Here: http://api.jquery.com/keypress/

Also you could have easily avoided this question by doing a simple Google search.

J D
  • 1,768
  • 2
  • 18
  • 20