tab key emulation

admin

Administrator
Staff member
Hello all,

I am fairly new to JavaScript. I am having some difficulty getting the tab key emulation script to work that is available off of the JavaScript Source website. Below you will find the pertinent code as it appears on the ASP produced page.

Here is the HEAD information:


<script language="JavaScript">
<!-- hide from JavaScript-challenged browsers
// Begin TAB key emulation
var nextfield ="CalledInBy";
var netscape ="";
var ver = navigator.appVersion;
var len = ver.length;
for(iln = 0; iln < len; iln++) if (ver.charAt(iln) == "(") break;
netscape = (ver.charAt(iln+1).toUpperCase() != "C");
function keyDown(DnEvents) {
var k = (netscape) ? DnEvents.which : window.event.keyCode;
// var k = window.event.keyCode;
if (k == 13) {
if (nextfield = "done") {
return true;
}
else {
eval('document.theForm.' + nextfield + '.focus()');
return false;
}
}
}
document.onkeydown = keyDown;
if (netscape) document.captureEvents(Event.KEYDOWN|Event.KEYUP);
// done hiding -->
</script>



Here is the BODY information:


<body OnLoad='document.theForm.CalledInBy.focus();'>

<td class='50ow'>Called In By: <input type='text' name='CalledInBy' value ='' size='20' onfocus='nextfield="CustLastName";' onblur='ckElement(this,0,25,"Called In By","TS");'>

<td class='50ow'>Last Name: <input type='text' name='CustLastName' value ='' size='30' onfocus='nextfield="CustFirstName";' onblur='ckElement(this,0,40,"Customer Last Name","TS");'></td>

<td class='50ow'>First Name: <input type='text' name='CustFirstName' value ='' size='30' onblur='ckElement(this,0,30,"Customer First Name","TS");'></td>

<input type='button' value='http://www.webdeveloper.com/forum/archive/index.php/Update Information' onclick='document.theForm.submit()'></td>



The form in and of itself works fine. The first thing I did was to 'disable' the enter key for form submission by using the onclick event. The second thing I wanted to do is to emulate the tab key when the enter key was pressed. With the code above, when the enter key is pressed nothing happens. I can still iterate the text fields by using tab. I get no run time errors with the code as it appears. I had also removed all of the netscape specific code because I only wanted to deal with IE, but that didn't work so I put the netscape code back in and still nothing. Any ideas?
 
Back
Top