473,569 Members | 2,770 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Unexpectedly showing me.. Object is Undefined.

2,476 Top Contributor
Let's see at my code fragment.
Expand|Select|Wrap|Line Numbers
  1. var checkBoxes = document.getElementsByTagName("input");
  2. for(var i=0;checkBoxes.length;i++){
  3.  if(checkBoxes[i].type.toLowerCase()=="checkbox" && checkBoxes[i].checked){
  4.  }
  5. }
Tell me, how checkBoxes[i] is undefined?
What may be the cause? ;)
Apr 8 '09 #1
10 1801
8,658 Recognized Expert Moderator Expert
you've got a syntax error* in line 2.
Expand|Select|Wrap|Line Numbers
  1. for(var i=0; checkBoxes.length; i++)
must be
Expand|Select|Wrap|Line Numbers
  1. for(var i=0; i < checkBoxes.length; i++)
* technicly it is not an error, but it's not sensible either
Apr 8 '09 #2
2,476 Top Contributor
S**** ... !! Anyway thanks!
Apr 8 '09 #3
8,658 Recognized Expert Moderator Expert
I've just had such a mistake myself.
Apr 8 '09 #4
5,390 Recognized Expert Moderator Expert
just a note to speed such nodelist-iterations up ;) ... you could use it the following way:

Expand|Select|Wrap|Line Numbers
  1. var nodes = document.getElementsByTagName('input');
  3. for (var i = 0, n; n = nodes[i]; ++i) {
  4.     if (n.type.toLowerCase() == 'checkbox' && n.checked) {
  5.         // checked checkbox
  6.     }
  7. }
kind regards
Apr 9 '09 #5
2,476 Top Contributor
How does it speed up? In which sense you are telling? :(
Apr 9 '09 #6
8,658 Recognized Expert Moderator Expert
and then we're using while-loops, just because we can. *g*
Apr 9 '09 #7
8,658 Recognized Expert Moderator Expert
I think because of n = nodes[i] (only one array access)
Apr 9 '09 #8
5,390 Recognized Expert Moderator Expert
exactly, we don't retrieve the array's length and we just use one array-access per step ... when nodes[i] is undefined the loop terminates ...

kind regards
Apr 9 '09 #9
2,476 Top Contributor
What do you mean by one array access?

Here two things happen..
First it copies the reference then check whether it is defined or undefined or Null.

But what slows down in my previous one?
Apr 9 '09 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

by: Niel | last post by:
Hello friends, I am not sure if i am posting to the correct group but if anyone has an idea about this and the possible solution or the link to that solution then please let me know We have out website running on Windows 2000 - IIS 5.0. Everything was working fine but since last few days my IIS Services get stopped unexpectedly. When i...
by: sneill | last post by:
How is it possible to take the value of a variable (in this case, MODE_CREATE, MODE_UPDATE, etc) and use that as an object property name? In the following example I want 'oIcon' object to have the properties: mode1, mode2, and mode3. This seems simple but I can't quite figure it out... Any ideas anyone?
by: Matt Sollars | last post by:
Hi all. I'm having a nasty problem. A client's website was originally written with classic ASP. They requested a new portion of the site that was deemed a perfect candidate for ASP.NET. So, .NET was installed on their web server and one of the subdirectories in the web site was converted to a virtual application to support the new pages...
by: phancey | last post by:
hi, I'm having an absolute nightmare with this! I've seen many posts on the subject but still can't quite figure it out. I'm using csharp and Framework 1.1.4322.537 on Windows2000 Professional 5.00.2195 Service Pack 4
by: Rocio | last post by:
Here I go again. Some time ago I wrote a VB.NET web service application that called a COM object written in VB6 using late binding. It was the only way I could call this object (see my posting in...
by: geneb | last post by:
I've got a number of tabs with text boxes on them. When you hit the last textbox on a tab, it checks to see if the next tab is a valid destination, then goes to it if so. Unfortunately, when this happens, both the Enter _and_ Leave events of the first textbox control are fired, causing all sorts of mayhem. On a related note, I have...
by: Paul Wasowicz | last post by:
Configuration: Windows 2000 Server SP4 ..Net Framework 1.1 SP1 Microsoft Site Server 3.0 Problem: the following error messages start showing up in the EVENT LOG on the server every once in a while until server becomes un-usable and has to be rebooted; users see in the browser Server Application Unavailable message; this seems to happen...
by: Frav | last post by:
The Reps team have been experiencing that Access 2002 unexpectedly quits while working and also lots of Corruption Failures and "Record lock can not update" messages since the upgrade from Windows 2000 and Access 200 to Windows XP and Access 2002 (XP) was done. Now, they are working and at anytime in anywhere of the application access...
by: Jon Paal | last post by:
anybody know what causes this error message reported by visual studio just in tiime debugger ? I get it when trying to populate a simple gridview from a datareader. Running locally, the code compiles, but after the page renders, I get the debugger popping up and it gives me the following error message "an unhandled...
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
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...
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...
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...
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...
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...
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
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 we have to send another system

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.