I use
this:
<script language="JavaScript">
var
isNN = (navigator.appName.indexOf("Netscape")!=-1);
function autoTab(input,len, e) {
var keyCode = (isNN) ? e.which : e.keyCode;
var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
if(input.value.length >= len && !containsElement(filter,keyCode)) {
input.value = input.value.slice(0, len);
input.form[(getIndex(input)+1) % input.form.length].focus();
}
function containsElement(arr, ele) {
var found = false, index = 0;
while(!found && index < arr.length)
if(arr[index] == ele)
found = true;
else
index++;
return found;
}
function getIndex(input) {
var index = -1, i = 0, found = false;
while (i < input.form.length && index == -1)
if (input.form[i] == input)index = i;
else i++;
return index;
}
return true;
}
</script>
function autoTab(input,len, e) {
var keyCode = (isNN) ? e.which : e.keyCode;
var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
if(input.value.length >= len && !containsElement(filter,keyCode)) {
input.value = input.value.slice(0, len);
input.form[(getIndex(input)+1) % input.form.length].focus();
}
function containsElement(arr, ele) {
var found = false, index = 0;
while(!found && index < arr.length)
if(arr[index] == ele)
found = true;
else
index++;
return found;
}
function getIndex(input) {
var index = -1, i = 0, found = false;
while (i < input.form.length && index == -1)
if (input.form[i] == input)index = i;
else i++;
return index;
}
return true;
}
</script>
Then
your text controls will be something like this:
<input type="Text" name="MM" maxlength="2" size="2" )>
<input type="Text" name="DD" maxlength="2" size="2" )>
<input type="Text" name="YY" maxlength="2" size="2" )>
-----Original Message-----
From: Sheeran, Jean [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, May 01, 2001 9:47 AM
To: '[EMAIL PROTECTED]'
Subject: JavaScript questionI have an area of my form that is set up for a date entry as follows:
__/__/__
mm dd yy
I would like to use JavaScript (or something better) to detect when 2 characters have been entered into the 'mm' field, and then to set focus to the 'dd' field. (then the same for the dd-> yy field) Essentially to the end user, it is as simple as just typing a string of 6 characters instead of having to 'Tab' through or click the next field. How does one achieve this?
