473,466 Members | 1,436 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 1391
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: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.