View Full Version : not selecting

06-03-2003, 10:30 PM
I am trying to move from one input box to another and then select the text in it. Below is a simplified version of what I'm trying to do. How come I can't select() the text when the focus comes from another input box, but will select() if I am already in the box? This is really weird :confused:

// sample code

<script type="text/javascript">
function moveToB() {
//get the key pressed in Netscape and IE
var keyCode =
document.layers ? evt.which :
document.all ? event.keyCode :
document.getElementById ? evt.keyCode : 0;

if (keyCode == 40) { // down arrow pressed
var obj = document.getElementById('b');
//why doesn't this work??
press the <b>down arrow</b> to move from box A to box B<br>
<form name="f">
<input type="text" id="a" onkeydown="moveToB()" value="boxA">
<input type="text" id="b" onkeydown="moveToB()" value="boxB">
moving from box A to B will not select the text in B, however moving from box B to B will.

06-03-2003, 11:58 PM
use onkeyup instead

06-04-2003, 12:06 AM
Sweet!! :thumbsup: I couldn't figure that out for the longest time... and to think, all I had to do was ask! :p