Click to See Complete Forum and Search --> : Replace Enter w/Tab


wgcampbell
10-02-2003, 04:56 PM
Complete novice here. I found the following script which replaces the enter key with a tab key (for data entry forms). It works fine, however, it doesn't show the focus (the nice little rectangular box) i.e. when it moves to a checkbox control. This happens only when you exclusively press all enter keys. Curiously, if you press a tab key (on some field), then the focus starts displaying properly again. Trying to utilize this script with asp.net.

============================
function disableEnterKey(){
if(event.keyCode == 13)
{
event.keyCode=9; //return the tab key
event.cancelBubble = true;
}
}
============================

Thanks for any help.

Khalid Ali
10-02-2003, 09:47 PM
post a link where you may have this working code....

wgcampbell
10-02-2003, 10:42 PM
Don't have a linked example, but here's an example page:
===================================
<html>
<head>
<title></title>
<SCRIPT LANGUAGE="JavaScript">
function disableEnterKey(){
if(event.keyCode == 13)
{
event.keyCode=9; //return the tab key
event.cancelBubble = true;
}
}
</script>
</head>
<body>
<center>
<form name=yourform ID="Form1">
Visual Focus Example<br>
Begin by 'mousing' into Box1 (do not press the [tab] key).<br>
Type some data, and press the [enter] key.<br>
Focus moves to Box2. Type some data, and press the [enter] key.<br>
Focus moves to ChkBx1, but no visible dotted rectangle.<br>
Once you press the [tab] key once, it behaves as one would expect.<br><br>
Box 1: <input type=text name=box1 onkeydown=disableEnterKey() ID="Text1"><br>
Box 2: <input type=text name=box2 onkeydown=disableEnterKey() ID="Text2"><br>
ChkBx1:<input type=checkbox name=checkbox1 onkeydown=disableEnterKey() id="Check1"><br>
Box 3: <input type=text name=box3 onkeydown=disableEnterKey() ID="Text3"><br>
<input type=submit name=done value="Submit" ID="Submit1">
</form>
</center>
</body>
</html>
=====================================

wgcampbell
10-03-2003, 07:52 PM
OK - after sending my example to another host, I discover that the behavior appears to be unique to the Visual Studio .net environment. Sorry for wasting time!

Geoff