[thelist] onKeypress Event

.jeff jeff at members.evolt.org
Mon Nov 11 04:51:01 CST 2002


stevenson,

><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
> From: Stevenson Ngila
>
> Using the div below,Is there a way on which i can attach
> my keyboard keys so that on key press i.e. "z", it
> scrolls the div with "zeke" name to view?
>
> 			<div id="all1">
> 				<div id="d1">peter</div>
> 				<div id="d2">john</div>
> 				<div id="d3">mark</div>
> 				<div id="d4">anna</div>
> 				<div id="d5">zeke</div>
> 				<div id="d6">mary</div>
> 			</div>
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><

sure, just change the outer <div></div> tags to a <select></select> tags.
then, change the inner <div></div> tags to <option></option> tags.

;p

seriously though, what you're asking isn't exactly easy.  you'll have to
decide where you want to attach event handlers to catch the onkeypress
event -- either the <body></body> tags or the outer <div></div> tags.  then,
you'll have to write a routine which will parse the inner <div></div> tags
innerText property.  you'll need to decide whether you want to stop
searching once you find the first div containing a string that begins with
the key the user pressed or if you want to scroll to the second instance if
the first is already in view or store the keys the user is typing and scroll
to the one who's first n characters matches n keys the user entered.  once
the contents have been scrolled into view, you've gotta decide how you're
going to indicate to the user which <div></div> tag's innerText matches.

i guess the things that pop into my head are questions like:

 - what's this being used for?
 - is it expected to accept input from the user beyond
   simply scrolling the inner <div></div> blocks into view?
 - what clues will there be to let the user know that this
   element reacts to keyboard use?

the answers to these questions would determine whether or not the
<div></div> idea you noted above plus all the scripting work i mentioned
above are warranted or if perhaps there's a better way of addressing the
need/problem.

.jeff

http://evolt.org/
jeff at members.evolt.org
http://members.evolt.org/jeff/




More information about the thelist mailing list