By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,576 Members | 1,462 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,576 IT Pros & Developers. It's quick & easy.

getElementById Help Needed ASAP

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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.