You'll need some stuff. First, set your script to read keyboard buttons. Note that this doesn't work for all keyboards. The keycode might be different, so try it out before you copy and paste.
document.onkeypress=keyDown
function keyDown()
{
if (event.keyCode == 30) {do_something} //Up Arrow
if (event.keyCode == 31) {do_something} //Down Arrow
}
Next, you have to have a script that finds which element is focused. Then it should move to the next element by using testform.some_element.focus() to put the user's insertion point in the newly focused element. Hope that helps.
the up and down arrow keys are typically used for scrolling the page.
if you're going to use them for something else, like navigating the form then you should check that a form element has the focus so that the original functionality of the page isn't broken too much.
anyway, you don't even need to do this. if you use the tabIndex attribute in your form elements, the form's users can press tab to go down the form fields, and press shift-tab to go up the form.
the tabIndex attribute takes numeric values to set the order.
can't you just inform the client that this is easier and better in the scheme of things.
here's a super crappy version that moves focus when pressing letter "d" - i got letter D and letter A figured out, but that's it - so if you keep it as is you have to make sure your users dont type anything with letter "d" ever goes it jumps right away
Code:
<html>
<head>
<script language="javascript">
var focusobj;
function dmove(k)
{
var code=-1
if(document.layers) code=k.which;
if(document.all) code=event.keyCode
if(code==100)
{
for (i=0;i<document.f.elements.length;i++)
{if (focusobj == document.f.elements[i])
{i++;
if (i>=document.f.elements.length) i=0;
document.f.elements[i].focus();
break;
}
}
}
}
function imatextfeild(obj)
{focusobj=obj;
}
if (document.layers)
{document.captureEvents(event.keypress);
}
document.onkeypress=dmove;
</script>
<head>
<body onload="focusobj=document.f.elements[0];">
<form name="f" id="f">
<input type="text" onFocus="imatextfeild(this);">
<input type="text" onFocus="imatextfeild(this);">
</form>
</body>
</html>
p.s. i didn't come up with that - i don't know who did, i found some scraps from a script i got a wihle back and did some very minor mods.
Hey that demo link was kinda cool! I was having some fun with it!
But I noticed a bug, if you hold the down arrow key so that it expands the screen down and starts scrolling, the cross-browser.com thing gets stuck down there.. it's funny to watch it go off the screen all over the place!
Edit:oops, nevermind, if you keep scrolling back up so that you shrink the page so there's no more scroll bar, the cross-browser.com thing comes back... still pretty freaked out though
Sadiq.
Last edited by sad69; 05-21-2004 at 12:46 AM..
Reason: nm..
Location: Los Angeles, CA Original Location: Philippines
Posts: 10,241
Thanks: 0
Thanked 112 Times in 111 Posts
Quote:
Originally Posted by jbot
anyway, you don't even need to do this. if you use the tabIndex attribute in your form elements, the form's users can press tab to go down the form fields, and press shift-tab to go up the form.
the tabIndex attribute takes numeric values to set the order.
can't you just inform the client that this is easier and better in the scheme of things.
It has keycodes for you to play with. I also believe tabIndex would be better, but who really cares? Its your web page and you can do what you want. I hope that helps.
but who really cares? Its your web page and you can do what you want.
Spoken like a true hobbyist
__________________
"Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark
I agree that using the tabIndex is the simplest way, but not many people know that using shift-tab makes you go back, so I'm with ksridhar69 on this one,
I need the form to 'act like' a excel spreadsheet, or as close to one as possible. I know I'm not going to be able to get select>drag>copy functionality working within the form [can I?], but using the arrow keys to navigate the from is a must.
I'll see what I can come up with and post the results here for you guys to pick holes in [pretty new at JavaScript].
I know I'm not going to be able to get select>drag>copy functionality working within the form [can I?]
you can. but because Moz doesn't support copy and paste operations without signed scripts, you'll need to hack together some clever DHTML to make it work. it's not difficult tho. just break it down into several steps and author functions or objects for each phase.
you can. but because Moz doesn't support copy and paste operations without signed scripts, you'll need to hack together some clever DHTML to make it work. it's not difficult tho. just break it down into several steps and author functions or objects for each phase.
I can? do you know of any posts, tutorials that would give me some further points on this? I haven’t got a clue where to start.