...

View Full Version : not selecting



snapp_action
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


<html>
<head>
<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');
obj.focus();
//why doesn't this work??
obj.select();
}
}
</script>
</head>
<body>
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">
</form>
moving from box A to B will not select the text in B, however moving from box B to B will.
</body>
</html>

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

snapp_action
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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum