473,397 Members | 2,033 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

best practice for navigating through a table with arrow keys?

PJ6
When I hit an arrow key, I want to be able to change the focus from cell to
cell just like in Excel. I see two ways of doing this. First, emitting in
script a function call in each cell on key down that specifically lists the
ID's of the adjacent controls. The second is to somehow put in some
navigation information into the ID's themselves and then loop through them
on key press to try to calculate which cell to go to next. Which is the
better technique? Are there others that may be better?

TIA,
Paul
Dec 3 '05 #1
2 3777
"PJ6" <no****@nowhere.net> wrote in message
news:Mqlkf.2647$1y.2159@trnddc07...
When I hit an arrow key, I want to be able to change the focus from cell to cell just like in Excel. I see two ways of doing this. First, emitting in
script a function call in each cell on key down that specifically lists the ID's of the adjacent controls. The second is to somehow put in some
navigation information into the ID's themselves and then loop through them
on key press to try to calculate which cell to go to next. Which is the
better technique? Are there others that may be better?

TIA,
Paul

Will this help? Watch for word-wrap. Test "as-is".

<html>
<head>
<title>arrows.htm</title>
<script type="text/javascript">
var b4 = "";
var col = 1;
var row = 1;
document.onkeyup = function() {
if (window.event) {
var key = window.event.keyCode;
window.status = key;
if (key == 37) { // left arrow
if (col > 1) col--;
} else if (key == 38) { // up arrow
if (row > 1) row--;
} else if (key == 39) { // right arrow
if (col < 5) col++;
} else if (key == 40) { // down arrow
if (row < 5) row++;
}
bg();
}
}
function bg() {
var rc = "r" + row + "c" + col;
if (b4 == "") b4 = rc;
document.getElementById(b4).style.backgroundColor = "white";
document.getElementById(rc).style.backgroundColor = "yellow";
b4 = rc;
}
</script>
</head>
<body onload="bg()">
<table border="1" width="500">
<tr height="75">
<th bgcolor="#FFFFFF" width="75"><sup>Use<br>Arrow<br>Keys</sup></th>
<th bgcolor="#EEEEEE" width="75"><sup>Col 1</sup></th>
<th bgcolor="#EEEEEE" width="75"><sup>Col 2</sup></th>
<th bgcolor="#EEEEEE" width="75"><sup>Col 3</sup></th>
<th bgcolor="#EEEEEE" width="75"><sup>Col 4</sup></th>
<th bgcolor="#EEEEEE" width="75"><sup>Col 5</sup></th>
</tr>
<tr height="75">
<th bgcolor="#EEEEEE"><sup>Row 1</sup></th>
<th id="r1c1">&nbsp;</th>
<th id="r1c2">&nbsp;</th>
<th id="r1c3">&nbsp;</th>
<th id="r1c4">&nbsp;</th>
<th id="r1c5">&nbsp;</th>
</tr>
<tr height="75">
<th bgcolor="#EEEEEE"><sup>Row 2</sup></th>
<th id="r2c1">&nbsp;</th>
<th id="r2c2">&nbsp;</th>
<th id="r2c3">&nbsp;</th>
<th id="r2c4">&nbsp;</th>
<th id="r2c5">&nbsp;</th>
</tr>
<tr height="75">
<th bgcolor="#EEEEEE"><sup>Row 3</sup></th>
<th id="r3c1">&nbsp;</th>
<th id="r3c2">&nbsp;</th>
<th id="r3c3">&nbsp;</th>
<th id="r3c4">&nbsp;</th>
<th id="r3c5">&nbsp;</th>
</tr>
<tr height="75">
<th bgcolor="#EEEEEE"><sup>Row 4</sup></th>
<th id="r4c1">&nbsp;</th>
<th id="r4c2">&nbsp;</th>
<th id="r4c3">&nbsp;</th>
<th id="r4c4">&nbsp;</th>
<th id="r4c5">&nbsp;</th>
</tr>
<tr height="75">
<th bgcolor="#EEEEEE"><sup>Row 5</sup></th>
<th id="r5c1">&nbsp;</th>
<th id="r5c2">&nbsp;</th>
<th id="r5c3">&nbsp;</th>
<th id="r5c4">&nbsp;</th>
<th id="r5c5">&nbsp;</th>
</tr>
</table>
</body>
</html>
Dec 3 '05 #2
PJ6
Yeah that works. I'll go with that variation then.

Thanks,
Paul

"McKirahan" <Ne**@McKirahan.com> wrote in message
news:eb********************@comcast.com...
"PJ6" <no****@nowhere.net> wrote in message
news:Mqlkf.2647$1y.2159@trnddc07...
When I hit an arrow key, I want to be able to change the focus from cell

to
cell just like in Excel. I see two ways of doing this. First, emitting in
script a function call in each cell on key down that specifically lists

the
ID's of the adjacent controls. The second is to somehow put in some
navigation information into the ID's themselves and then loop through
them
on key press to try to calculate which cell to go to next. Which is the
better technique? Are there others that may be better?

TIA,
Paul

Will this help? Watch for word-wrap. Test "as-is".

<html>
<head>
<title>arrows.htm</title>
<script type="text/javascript">
var b4 = "";
var col = 1;
var row = 1;
document.onkeyup = function() {
if (window.event) {
var key = window.event.keyCode;
window.status = key;
if (key == 37) { // left arrow
if (col > 1) col--;
} else if (key == 38) { // up arrow
if (row > 1) row--;
} else if (key == 39) { // right arrow
if (col < 5) col++;
} else if (key == 40) { // down arrow
if (row < 5) row++;
}
bg();
}
}
function bg() {
var rc = "r" + row + "c" + col;
if (b4 == "") b4 = rc;
document.getElementById(b4).style.backgroundColor = "white";
document.getElementById(rc).style.backgroundColor = "yellow";
b4 = rc;
}
</script>
</head>
<body onload="bg()">
<table border="1" width="500">
<tr height="75">
<th bgcolor="#FFFFFF" width="75"><sup>Use<br>Arrow<br>Keys</sup></th>
<th bgcolor="#EEEEEE" width="75"><sup>Col 1</sup></th>
<th bgcolor="#EEEEEE" width="75"><sup>Col 2</sup></th>
<th bgcolor="#EEEEEE" width="75"><sup>Col 3</sup></th>
<th bgcolor="#EEEEEE" width="75"><sup>Col 4</sup></th>
<th bgcolor="#EEEEEE" width="75"><sup>Col 5</sup></th>
</tr>
<tr height="75">
<th bgcolor="#EEEEEE"><sup>Row 1</sup></th>
<th id="r1c1">&nbsp;</th>
<th id="r1c2">&nbsp;</th>
<th id="r1c3">&nbsp;</th>
<th id="r1c4">&nbsp;</th>
<th id="r1c5">&nbsp;</th>
</tr>
<tr height="75">
<th bgcolor="#EEEEEE"><sup>Row 2</sup></th>
<th id="r2c1">&nbsp;</th>
<th id="r2c2">&nbsp;</th>
<th id="r2c3">&nbsp;</th>
<th id="r2c4">&nbsp;</th>
<th id="r2c5">&nbsp;</th>
</tr>
<tr height="75">
<th bgcolor="#EEEEEE"><sup>Row 3</sup></th>
<th id="r3c1">&nbsp;</th>
<th id="r3c2">&nbsp;</th>
<th id="r3c3">&nbsp;</th>
<th id="r3c4">&nbsp;</th>
<th id="r3c5">&nbsp;</th>
</tr>
<tr height="75">
<th bgcolor="#EEEEEE"><sup>Row 4</sup></th>
<th id="r4c1">&nbsp;</th>
<th id="r4c2">&nbsp;</th>
<th id="r4c3">&nbsp;</th>
<th id="r4c4">&nbsp;</th>
<th id="r4c5">&nbsp;</th>
</tr>
<tr height="75">
<th bgcolor="#EEEEEE"><sup>Row 5</sup></th>
<th id="r5c1">&nbsp;</th>
<th id="r5c2">&nbsp;</th>
<th id="r5c3">&nbsp;</th>
<th id="r5c4">&nbsp;</th>
<th id="r5c5">&nbsp;</th>
</tr>
</table>
</body>
</html>

Dec 3 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: skipc | last post by:
Hi, I am stuck... I've got a popup window that displays a list in table format with links on the bottom to navigate the list <prev> 1 2 3 ... <next> When I demo'd to the users... they...
2
by: Darren Oakey | last post by:
ok - the problem - I made a simple breakout game out of a form, just painting the background - and using keydown for left and right arrow keys to control the bat - worked fine. I then moved all...
4
by: Neil Wallace | last post by:
Hi there, I have an application in which a grid of 100 or more buttons are put on a form in columns of 10. All the buttons are within a panel. They are added in runtime, and so they adopt a...
11
by: Rlrcstr | last post by:
How can you detect when an arrow key gets pressed? Doesn't seem to trigger a KeyPress or KeyDown event. Thanks. Jerry
2
by: Vincent | last post by:
Hi, I have a user control that needs to trap the arrow keys to move items around internally. However, using the arrow keys will move the focus to another control on the form hosting the user...
16
by: Rex | last post by:
Hi All - I have a question that I think MIGHT be of interest to a number of us developers. I am somewhat new to VIsual Studio 2005 but not new to VB. I am looking for ideas about quick and...
1
by: Martijn Mulder | last post by:
/* I have problems detecting the Arrow Keys on a User Control. A control derived from System.Windows.Forms.Control neglects 'bare' Arrow Keys but does react on the combination <Altor <Ctrl+ Arrow...
0
by: Martijn Mulder | last post by:
/* I override IsInputKey() to direct the Arrow Keys (Cursor Keys) to my custom System.Windows.Forms.Control. But, holding down the Shift-Key prevents the Arrow Keys from coming through. How can...
4
by: boopsboops | last post by:
Hi thescripts people, I hope I'm in the right forum for Visual Basic Dotnet (VS 2005). I am trying to make a custom control in which you can nudge a point around using the arrow keys. Actually,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.