471,089 Members | 1,318 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,089 software developers and data experts.

getElementById Help Needed ASAP

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[i] = 'antirobot';
i++;
}

if (!checkform.chk_agree.checked){
invalid_array[i] = '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;
}
Jul 23 '05 #1
2 1260
SC
Nevermind. It figures that immediately after I post this message, I fix the
problem.

Thanks anyway!

"SC" <no*****@thank.you> wrote in message
news:8t****************@news.uswest.net...
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[i] = 'antirobot';
i++;
}

if (!checkform.chk_agree.checked){
invalid_array[i] = '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;
}

Jul 23 '05 #2
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()

Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Greg | last post: by
10 posts views Thread by Rich Hephner | last post: by
27 posts views Thread by VK | last post: by
reply views Thread by help_wanted | last post: by
1 post views Thread by Massimo Bonanni | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.