getElementById Help Needed ASAP

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;
}
 
S

SC

Nevermind. It figures that immediately after I post this message, I fix the
problem.

Thanks anyway!
 
L

Lee

SC said:
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.

It looks to me as if at least some of the names are NOT right.
Have you tried alert()ing the id values just before using
getElementById()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Homework in C - Help Needed 1
Help With a Script 5
HELP WITH MediaSource 2
Help :( 3
Help with code 0
DJForm Login Help! 1
Help needed with code 5
Help with my responsive home page 2

Members online

No members online now.

Forum statistics

Threads
474,265
Messages
2,571,069
Members
48,771
Latest member
ElysaD

Latest Threads

Top