I have a javascript that no longer works, and I'm not a JS programmer (yet). It's setup for 4 text fields for entering IP octets, and it's supposed to change focus after entering the 3rd character in each box. I'm not sure why it fails now.
Also, I want to adjust the script so that when it shifts focus, it selects all the existing text in the box, not put the cursor at the beginning of the text.
Here's the old scripting:
<SCRIPT LANGUAGE="JAVASCRIPT">
// Set some variables
var octet1Length = 2
var octet2Length = 2
var octet3Length = 2
//
// This function checks if the given character is a digit.
function isDigit (c)
{
return ((c >= "0"
&& (c <= "9"
)
}
//
// This function checks if the given string is an integer
function isInteger (s)
{ var i;
for (i = 0; i < s.length; i++) {
var c = s.charAt(i);
if (!isDigit(c)) return false;
}
return true;
}
//
function handleTabs(name) {
if (name == "octet1"
{
if ( ( isInteger(document.form1.octet1.value) ) &&
( document.form1.octet1.value.length == octet1Length )
) {
document.form1.octet2.focus();
}
}
if (name == "octet2"
{
if ( ( isInteger(document.form1.octet2.value) ) &&
( document.form1.octet2.value.length == octet2Length )
) {
document.form1.octet3.focus();
}
}
if (name == "octet3"
{
if ( ( isInteger(document.form1.octet3.value) ) &&
( document.form1.octet3.value.length == octet3Length )
) {
document.form1.octet4.focus();
}
}
}
</script>
--------later in the body:
<TD>
<input NAME="octet1" TYPE="text" SIZE="3" MAXLENGTH="3" VALUE="1" onKeyPress="handleTabs('octet1')">
<input NAME="octet2" TYPE="text" SIZE="3" MAXLENGTH="3" VALUE="1" onKeyPress="handleTabs('octet2')">
<input NAME="octet3" TYPE="text" SIZE="3" MAXLENGTH="3" VALUE="1" onKeyPress="handleTabs('octet3')">
<input NAME="octet4" TYPE="text" SIZE="3" MAXLENGTH="3" VALUE="1" onKeyPress="handleTabs('octet4')"> </td>
</td>
Thanks,
Eman Erin Quick-Laughlin
DBA, PHP/MySQL programmer
Also, I want to adjust the script so that when it shifts focus, it selects all the existing text in the box, not put the cursor at the beginning of the text.
Here's the old scripting:
<SCRIPT LANGUAGE="JAVASCRIPT">
// Set some variables
var octet1Length = 2
var octet2Length = 2
var octet3Length = 2
//
// This function checks if the given character is a digit.
function isDigit (c)
{
return ((c >= "0"
}
//
// This function checks if the given string is an integer
function isInteger (s)
{ var i;
for (i = 0; i < s.length; i++) {
var c = s.charAt(i);
if (!isDigit(c)) return false;
}
return true;
}
//
function handleTabs(name) {
if (name == "octet1"
if ( ( isInteger(document.form1.octet1.value) ) &&
( document.form1.octet1.value.length == octet1Length )
) {
document.form1.octet2.focus();
}
}
if (name == "octet2"
if ( ( isInteger(document.form1.octet2.value) ) &&
( document.form1.octet2.value.length == octet2Length )
) {
document.form1.octet3.focus();
}
}
if (name == "octet3"
if ( ( isInteger(document.form1.octet3.value) ) &&
( document.form1.octet3.value.length == octet3Length )
) {
document.form1.octet4.focus();
}
}
}
</script>
--------later in the body:
<TD>
<input NAME="octet1" TYPE="text" SIZE="3" MAXLENGTH="3" VALUE="1" onKeyPress="handleTabs('octet1')">
<input NAME="octet2" TYPE="text" SIZE="3" MAXLENGTH="3" VALUE="1" onKeyPress="handleTabs('octet2')">
<input NAME="octet3" TYPE="text" SIZE="3" MAXLENGTH="3" VALUE="1" onKeyPress="handleTabs('octet3')">
<input NAME="octet4" TYPE="text" SIZE="3" MAXLENGTH="3" VALUE="1" onKeyPress="handleTabs('octet4')"> </td>
</td>
Thanks,
Eman Erin Quick-Laughlin
DBA, PHP/MySQL programmer