Submit Your Article Forum Rules

Results 1 to 3 of 3

Thread: Javascript undefined

  1. #1
    Senior Member
    Join Date
    Apr 2006
    Location
    Boulder, CO USA
    Posts
    371

    Javascript undefined

    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>

  2. #2
    Senior Member
    Join Date
    Dec 2007
    Posts
    526
    Quote Originally Posted by blitzen View Post
    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...

    Code:
    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 = [[""],[""],[""],[""]];

  3. #3
    Senior Member
    Join Date
    Apr 2006
    Location
    Boulder, CO USA
    Posts
    371
    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!
    Last edited by blitzen; 03-08-2011 at 04:18 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •