473,770 Members | 6,515 Online
Bytes | Software Development & Data Engineering Community
+ 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.anti robot.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.layer s){
document.images[id].src = "images/icon_warning.gi f";
} else if (document.getEl ementById){
document.getEle mentById(id).sr c = "images/icon_warning.gi f";
}
}
return false;
} else {
document.formRe gister.Submit.d isabled=true;
return true;
}
Jul 23 '05 #1
2 1411
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.u swest.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.anti robot.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.layer s){
document.images[id].src = "images/icon_warning.gi f";
} else if (document.getEl ementById){
document.getEle mentById(id).sr c = "images/icon_warning.gi f";
}
}
return false;
} else {
document.formRe gister.Submit.d isabled=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
9592
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 text field QuantityMade holds a value of 17)
3
36183
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 rewrite it so that it's W3C compliant. Reading through earlier messages I concluded I should go with getElementById but this doesn't work. What am I doing wrong? Your help is much appreciated.
10
1423
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; charset=iso-8859-1"> <script language="javascript"> alert(document.getElementById('pst'));
27
2542
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 check these first:- <http://developer.irt.org/script/script.htm>
0
1108
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 have detailed knowledge of performance tuning of OLTP and OLAP databases on DB2 platform. Experience with partitioning and heavy duty technical stuff. Experience with ERP's, particularly PeopleSoft is a plus. We'll provide a fast paced,...
1
1654
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
2994
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 as fast as possible. I have about 10-20 id tags that need to be accessed and modified from time to time. Would the jvm perform slowly if I stored all of the dom node strings "document.node.child...." into a huge js array?
3
2411
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, and was hoping to make the JavaScript reusable, passing it the name of the fields that need to change, but I'm having some trouble. In particular, I'm having trouble here: ------------
6
1833
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 (!document.getElementById) document.getElementById = function(id) { return document.all; } This should then provide a getElementById function if one does not already
0
10058
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10004
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9870
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8886
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7416
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6678
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5450
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3576
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2817
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.