View Full Version : JavaScript and JSF: Question regarding dataTable/onkeypress and key-recognition

08-21-2008, 06:43 AM
I earlier posted this message over at the Sun Forums;

I'm have made a dataTable and want;

1. ...to be able to highlight one row (and activate some other functionality) by clicking on it with the mouse

2. ...and then move up or down in the rows with the arrow keys.

I have been able to do the first with rowOnClick and JavaScript, but for the latter I can't seem to figure out where to place rowOnKeyPress or onkeypress to get my JavaScript code to run.

I have used onkeypress with inputText before, and it works well when you enter a letter, but how do you get it to work when you have a dataTable with only outputText?...and got this reply:

Invoke a piece of JavaScript on load of the page which gets the table element, crawls through all of its tr elements and adds the new onkeypress functions to it. The onkeypress function on its turn must determine the key pressed and then set the focus (and highlight) to one row up or down in the table.

I won't go in code detail as you aren't at a JavaScript forum, but you can get some ideas out of here. If you still stucks, I recommend posting the question at a JavaScript forum. There are ones at webdeveloper.com and dynamicdrive.com.I'm not sure quite how to go about this, so any pointers in the right direction would be greatly appreciated.