473,385 Members | 1,622 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,385 software developers and data experts.

Unexpectedly showing me.. Object is Undefined.

dmjpro
2,476 2GB
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. }
  6.  
Tell me, how checkBoxes[i] is undefined?
What may be the cause? ;)
Apr 8 '09 #1
10 1796
Dormilich
8,658 Expert Mod 8TB
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
dmjpro
2,476 2GB
S**** ... !! Anyway thanks!
Apr 8 '09 #3
Dormilich
8,658 Expert Mod 8TB
I've just had such a mistake myself.
Apr 8 '09 #4
gits
5,390 Expert Mod 4TB
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');
  2.  
  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
dmjpro
2,476 2GB
How does it speed up? In which sense you are telling? :(
Apr 9 '09 #6
Dormilich
8,658 Expert Mod 8TB
and then we're using while-loops, just because we can. *g*
Apr 9 '09 #7
Dormilich
8,658 Expert Mod 8TB
@dmjpro
I think because of n = nodes[i] (only one array access)
Apr 9 '09 #8
gits
5,390 Expert Mod 4TB
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
dmjpro
2,476 2GB
@Dormilich
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
gits
5,390 Expert Mod 4TB
to use multiple checkBoxes[i] calls is not optimal ...
Apr 9 '09 #11

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

Similar topics

4
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...
16
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...
2
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...
4
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...
0
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...
1
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...
1
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...
2
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...
5
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

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.