Jquery key

Moti Mashiah
Moti Mashiah used Ask the Experts™
on
HI Guys,

I have asp.net mvc application and I'm trying to use keydown and keyup function to let my user to travel between rows by entering buttons pageup\pagedown.

I did something like this:

which didn't work so far.

$(document).keydown(function (e) {
        //alert(e.keyCode);
        $('input').keyup(function (e) {
            if (e.which == 33) { 
                $(this).closest('td').next().find('input').focus();

            } else if (e.which == 34) {
                $(this).closest('td').prev().find('input').focus();
            }
        });
        
    });

Open in new window


Please any suggestions.

Thanks,
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2013
Awarded 2012
Commented:
Hi,
why do you bind two different events on two different objects?

Could you please try the following:
$(document).ready(function() {
	$('input').keyup(function (e) {
    // 33 - Page Up
    // 34 - Page Down
    if (e.which == 34) { 
			$(this).closest('tr').next("tr").find('input').focus();
		} else if (e.which == 33) {
      $(this).closest('tr').prev("tr").find('input').focus();
		}
  });
});

Open in new window


Not sure about your HTML DOM structure, but using the TR instead of the TD and only binding the Event to the INPUT elements did the trick.

Live sample:
https://jsfiddle.net/EE_RainerJ/47afowju/16/

HTH
Rainer
Moti Mashiah.NET Developer

Author

Commented:
Thank you very much that was solving my issue.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial