I have a form that gets built dynamically with php and mysql.
I have JS functions that color the field when onfocus then back to normal onblur. This has always worked. Now I am dealing with a field that if a unit (from a dealership) is a licensed vehicle I have to force them to enter in 17 digit VIN.
What I am trying to do is if they enter one of these fields, and try to leave without typing anything (I do not want them stuck there with alerts never being able to leave) it is fine it just colors it while they are in and onblur normal. But if they are in one of these fields and it is a forceVIN unit and they type less than 17 digits, I want to alert them then place the focus back inot that same field.
Here is what I have, right now the alert works in mozilla and places the focus in another field with both being colored. IE once you try to onblur you have a alert loop you can not get out of unless you shut down IE.
form name is receive. Thanks for any help
[code]
<SCRIPT LANGUAGE=”JavaScript”>
<!–this is for our onfocus field colors–>
function chgit(chgit)
{
chgit.style.backgroundImage=”url(../images/box2_bg.gif)”;
}
// old color
function chgback(chgit)
{
chgit.style.backgroundImage=”url(../images/box_bg.gif)”;
}
// old color and handles our force 17 digit vin as well
function chgback2(chgit)
{
if (chgit.value.length !=”17″)
{
alert (“This unit is a licensed vehicle and must a 17 digit VIN”);
chgit.focus();
return false;
}
chgback(chgit);
}
</script>
[code]
//here we check to see if we are forcing a 17 digit VIN
if ($row[“ForceVIN”] == 1)
$value .= “<input type=text name=serial”.$j.” size=20 maxlength=20 value=”” onFocus=”chgit(this)” onBlur=”chgback2(this)”>”;
else
$value .= “<input type=text name=serial”.$j.” size=20 maxlength=20 value=”” onFocus=”chgit(this)” onBlur=”chgback(this)”>”;