PDA

View Full Version : Javascript undefined



blitzen
03-08-2011, 01:00 PM
Hello,
I have this in a Javascript. The Error Console is complaining that pnum line is undefined in the last line.
I can't figure out why. Can you?

<snip>
var pnum = [
[["","",""],["","",""],["","",""]],
[["","",""],["","",""],["","",""]],
[["","",""],["","",""],["","",""]],
[["","",""],["","",""],["","",""]],
];

pnum[0][3][1] = "1538|4|24|28|1";
<snip>

MrGamm
03-08-2011, 04:05 PM
Hello,
I have this in a Javascript. The Error Console is complaining that pnum line is undefined in the last line.
I can't figure out why. Can you?

<snip>
var pnum = [
[["","",""],["","",""],["","",""]],
[["","",""],["","",""],["","",""]],
[["","",""],["","",""],["","",""]],
[["","",""],["","",""],["","",""]],
];

pnum[0][3][1] = "1538|4|24|28|1";
<snip>

Javascript doesn't initialize arrays automatically. They have to be specifically delcared for each node level deep it goes. Which you have done, but it an array pointer starts at ZERO.

It can most likely be rewritten like this...




var pnum = [
[["","",""],["","",""],["","",""],["","",""]],
[["","",""],["","",""],["","",""],["","",""]],
[["","",""],["","",""],["","",""],["","",""]],
[["","",""],["","",""],["","",""],["","",""]],
];

pnum[0][3][1] = "1538|4|24|28|1";

This pnum[0] is...

var pnum = [];

This pnum[0][0] is...

var pnum = [[""]];

This pnum[0][1] is...

var pnum = [[""],[""]];

This pnum[0][2] is...

var pnum = [[""],[""],[""]];

This pnum[0][3] is...

var pnum = [[""],[""],[""],[""]];

blitzen
03-08-2011, 04:14 PM
Oh - thank you for the keen eye, and brain :)
That's why my product numbers didn't show up for this complex configured product.
They do now!