S
SC
I'm having a problem getting this validation script to work. There are two
images on the page with the ids of img_antirobot and img_chk_agree. In the
final page it will validate about 12 entries, so this is just a snippet. If
there are blank entries, the script is to change the appropriate images to
warning icons. Unfortunately it aways errors at the getElementById with
"undefined" as the reason. I know the names are right, so what's the
problem? I need to get this done ASAP so if anybody could help, it would be
greatly appreciated.
Thanks
SCRIPT
---------
var i = 0;
invalid_array = new Array();
if (checkform.antirobot.value == ""){
invalid_array = 'antirobot';
i++;
}
if (!checkform.chk_agree.checked){
invalid_array = 'chk_agree';
i++;
}
if (i > 0){
var x=0;
for (x=0; x<i; x++){
id = "img_" + invalid_array[x];
if (document.layers){
document.images[id].src = "images/icon_warning.gif";
} else if (document.getElementById){
document.getElementById(id).src = "images/icon_warning.gif";
}
}
return false;
} else {
document.formRegister.Submit.disabled=true;
return true;
}
images on the page with the ids of img_antirobot and img_chk_agree. In the
final page it will validate about 12 entries, so this is just a snippet. If
there are blank entries, the script is to change the appropriate images to
warning icons. Unfortunately it aways errors at the getElementById with
"undefined" as the reason. I know the names are right, so what's the
problem? I need to get this done ASAP so if anybody could help, it would be
greatly appreciated.
Thanks
SCRIPT
---------
var i = 0;
invalid_array = new Array();
if (checkform.antirobot.value == ""){
invalid_array = 'antirobot';
i++;
}
if (!checkform.chk_agree.checked){
invalid_array = 'chk_agree';
i++;
}
if (i > 0){
var x=0;
for (x=0; x<i; x++){
id = "img_" + invalid_array[x];
if (document.layers){
document.images[id].src = "images/icon_warning.gif";
} else if (document.getElementById){
document.getElementById(id).src = "images/icon_warning.gif";
}
}
return false;
} else {
document.formRegister.Submit.disabled=true;
return true;
}