...

View Full Version : javascript pressing enter to tab won't select textfield



uwajes
08-25-2004, 03:19 PM
I have a webpage where I have a form set up to tab to the next field when the user presses enter. The problem is that there is existing data in fields sometimes and the cursor instead of highlighting the existing text, places itself in front of the text. Not good.

This is for a handheld scanner/pda, so the user can't hit tab or click with a mouse.

So, the ideal situation is for when the user presses enter, that the next field is highlighted so the text can be replaced. Any ideas how I could accomplish this?

Code for js



<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
nextfield = "Product"; // name of first box on page
netscape = "";
ver = navigator.appVersion; len = ver.length;
for(iln = 0; iln < len; iln++) if (ver.charAt(iln) == "(") break;
netscape = (ver.charAt(iln+1).toUpperCase() != "C");

function keyDown(DnEvents) { // handles keypress
// determines whether Netscape or Internet Explorer
k = (netscape) ? DnEvents.which : window.event.keyCode;
if (k == 13) { // enter key pressed
if (nextfield == 'begin') return true; // submit, we finished all fields
else { // we're not done yet, send focus to next box
eval('document.yourform.' + nextfield + '.focus()');
return false;
}
}
}
document.onkeydown = keyDown; // work together to analyze keystrokes
if (netscape) document.captureEvents(Event.KEYDOWN|Event.KEYUP);
// End -->
</script>


Code for textfield

<input name="Product" onclick="this.focus();this.select();" onFocus="nextfield ='PO';"
type="Text" value="<!--[CBW.Data=Product]-->" size="15">

Willy Duitt
08-25-2004, 03:24 PM
So, the ideal situation is for when the user presses enter, that the next field is highlighted so the text can be replaced. Any ideas how I could accomplish this?

Try using select() as opposed to focus()....

.....Willy

uwajes
08-25-2004, 03:35 PM
That worked...Thanks!

Willy Duitt
08-25-2004, 03:42 PM
:thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum