473,513 Members | 2,693 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Why am I receiving 'undefined' error when setting a variable?

34 New Member
I am trying to compare a variable to what the variable previously was in the for loop. I run into a problem when I try to reset 'PAsubtotal'

The problem arises on the line:

PAsubtotal=0;

I get the error: "'undefined' is null or not an object"


Expand|Select|Wrap|Line Numbers
  1.  
  2. var details = new Array();
  3.     var cntr=0;
  4.     var PAtemp = new String();
  5.     var PAsubtotal;
  6.  
  7.     for( var current in me.items ){  
  8.         var item = me.items[current];                 
  9.         /*This is where I set matrix values*/        
  10. PAsubtotal = PAsubtotal + item.price*item.quantity
  11.  
  12.         if (cntr > 0){
  13.             if (!(item.size == PAtemp)){
  14.                 cntr++;
  15.                 details[cntr][5]= "<TD><b>" + PAsubtotal + "</b></TD></TR>";
  16.                 PAsubtotal=0;
  17.             }
  18.         }
  19.  
  20.         cntr++;
  21.         PAtemp = item.size;
  22.         } 
  23.  
Dec 6 '10 #1
8 1510
Dormilich
8,658 Recognized Expert Moderator Expert
this error usually appears when an object method is called.

in your case it is probably on line 15. if details[cntr] is not defined (e.g. if cntr is the same as the array length) details[cntr][5] will throw this error.
Dec 6 '10 #2
damicomj
34 New Member
Sorry, I left some code out. Up above I have, /*This is where I set matrix values*/

This is the code I have in there:

Expand|Select|Wrap|Line Numbers
  1.  
  2.         details[cntr]=new Array(5);
  3.         details[cntr][0]= "<TR><TD>" + item.name + "</TD>";
  4.         details[cntr][1]= "<TD>" + item.size + "</TD>";
  5.         details[cntr][2]= "<TD>" + item.color + "</TD>";
  6.         details[cntr][3]= "<TD>" + item.price + "</TD>";
  7.         details[cntr][4]= "<TD>" + item.quantity + "</TD>";
  8.         details[cntr][5]= "<TD>" + item.price*item.quantity + "</TD></TR>";
  9.         PAsubtotal = PAsubtotal + item.price*item.quantity
  10.  
  11.         alert(details[cntr]);
  12.  
Dec 6 '10 #3
Dormilich
8,658 Recognized Expert Moderator Expert
the problem is still the same, if cntr reaches details.length, you try to access a not existing array object.
Dec 6 '10 #4
damicomj
34 New Member
I am a bit confused. I add one to cntr in the if statement, which should bring the matrix to the next line. I just this to fill in the other columns, but it didn't help. Can you provide a suggestion for me?

Expand|Select|Wrap|Line Numbers
  1.                 details[cntr][0]= "<TR><TD> </TD>";
  2.                 details[cntr][1]= "<TD> </TD>";
  3.                 details[cntr][2]= "<TD> </TD>";
  4.                 details[cntr][3]= "<TD> </TD>";
  5.                 details[cntr][4]= "<TD> </TD>";
  6.                 details[cntr][5]= "<TD><b>" + PAsubtotal + "</b></TD></TR>";
  7.                 PAsubtotal=0;
  8.  
Dec 6 '10 #5
Dormilich
8,658 Recognized Expert Moderator Expert
no. you have a two-dimensional matrix, but your counter variable only increments the first level array.
Dec 6 '10 #6
damicomj
34 New Member
Okay, as an example, let's say cntr = 1.

The code in the If statement will get executed because cntr > 0. cntr++ will increment itself to 2.
Expand|Select|Wrap|Line Numbers
  1. details[2][5]= "<TD><b>" + PAsubtotal + "</b></TD></TR>"; 
is giving me the error. I don't see what is wrong with this line because I was using the same code outside of the If statement. Sorry if this is annoying, I am trying to talk myself through it.
Dec 6 '10 #7
Dormilich
8,658 Recognized Expert Moderator Expert
what does details.length give you?
Dec 6 '10 #8
damicomj
34 New Member
Okay, I defined the array inside of the If statement like you said, and I think I am all set now.

details[cntr]=new Array(5);

thank you
Dec 6 '10 #9

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

Similar topics

2
1549
by: skeeterbug | last post by:
i have a program that will display a number of diffferent results depending on the situation. one example of the code looks like <?php if(isset($_SESSION)) { print 'You entered: ' ....
2
1789
by: Carl Ganz | last post by:
In the code below I get an Internal SQL Server error in Query Analyzer. Ultimately I want to get thos code working in a function. DECLARE @WeekNumber tinyint DECLARE @Comp decimal(18,2) DECLARE...
0
1239
by: Eric B | last post by:
Hi. I'm trying to set the background of a form from a file with this code : Stream imgStream= File.Open("images\\popupbackground.jpg",FileMode.Open, FileAccess.Read, FileShare.Read);...
0
1987
by: Jeremy Chapman | last post by:
In an asp.net page, I'm creating an exchange account. I've created the account, and tied it to a primary NT account. Now I'm trying to assign permissions to it but I get an error of "The...
1
1859
by: effendi | last post by:
Hi I downloaded MSDE2005 and I tried to set up an ODBC connection to a database I created. I can see the database using client but I got this error through the ODBC manager An error has occurred...
0
963
by: SteMc | last post by:
I have one browser named "Main_Browser" and a second named "Secondary_Browser". I can set the height and width of the first wonderfully. I have a menu item that when pressed attempts to set the...
0
8229
acoder
by: acoder | last post by:
Problem When setting the FORM object's action property an "Object does not support this property or method" error occurs Browser Internet Explorer 6- Example The Javascript code: var...
6
3214
by: SunshineInTheRain | last post by:
can anyone please help me on problem of 'Sys' is undefined error? I know a lot forum has discussed about this, but none i success to solve the error. I have run it on Window server 2000, IIS 5,...
3
1629
by: BL3WC | last post by:
Hi, I encountered an error "Object not supporting this properties or method" while trying to set a checkbox value to 'True" in a loop. The VBA code I use is as follow: Set a value to intcount...
16
1904
by: manutd7 | last post by:
Hi, Every time I try to access the contents of the following array it returns that it is undefined. I have tried multiple variations on accessing the arrays syntax wise but get different errors...
0
7257
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
7157
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7379
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
7535
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...
1
7098
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...
1
5084
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...
0
4745
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
3221
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1591
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.