473,289 Members | 1,896 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,289 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 1382
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Greg | last post by:
I'm trying to understand getElementByID a bit better. When I try the following... if (parseFloat(document.getElementByID('QuantityMade').value) > 0) { alert('it seems to exist'); } (the...
3
by: sofie | last post by:
Hello all, I use the following javascript function in a html document to set the level of one of eight available radiobuttons. The line that's commented out works fine under IE, but I need to...
10
by: Rich Hephner | last post by:
Why isn't this working? <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html;...
27
by: VK | last post by:
<http://www.jibbering.com/faq/#FAQ3_2> The parts where update, replacement or add-on is needed are in <update> tag. 3.2 What online resources are available? Javascript FAQ sites, please...
0
by: help_wanted | last post by:
I'm on a development project that needs an experienced DB2 DBA. We need a serious, experienced, senior database administrator who can do DB2 and Unix shell scripting in his/her sleep. Person must...
1
by: Massimo Bonanni | last post by:
Hi, I try to implement ASAP protocol in my web service, but I find a very hard problem. I define my SOAP Header: public class Request : SoapHeader {
11
by: ctman770 | last post by:
Hi Everyone, Is it faster to save the precise location of an html dom node into a variable in js, or to use getElementById everytime you need to access the node? I want to make my application...
3
by: mikemcleod | last post by:
Hello everyone, Long time lurker, first time poster. I'm trying to implement an AJAX inline editor and am having some trouble. I want to use this editing field several times on the same page,...
6
by: Aaron Gray | last post by:
Hi, I know the 'document.getElementById()' issue is really over since every browser since 1998 supports the W3C DOM standard, but I could not resist this offering :- if...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...

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.