Results 1 to 2 of 2

Thread: Getting value from associative array

  1. #1
    Join Date
    Jun 2005

    Unhappy Getting value from associative array

    I have a page for an online store that contains 3 different items that can be bought in 3 different colors and 2 different sizes. I am using PayPal which gave me 10-character ids for each item, though I also use another nomenclature to distinguish between them. I use the first letter of the item, the first letter of the color (luckily there are no duplicates like blue and black) then the size using _ where / would be. This forms a string such as bb1_8 or tw1_4. I have created an associative array using these strings for the keys and the 10-character IDs as the values. So I have the following:
    var hookID = new Array();
    hookID["bb1_8"] = "LSADAMANTMZU8";
    hookID["tw1_4"] = "RD3D42AK8EPDN";
    hookID["bb1_4"] = "T94QFP82RW78J";
    The problem I'm having is when I try to get the ID value out of the array. When I use:
    I don't get anything. Instead, an error occurs saying "Unable to get property 'bb1_8' of undefined or null reference". I don't understand why I can't get the values out. Obviously, I wouldn't use a hard-coded id, but if I can't get even a hard-coded one, how will I get one that is variable?

    Please Help,
    Chris Cote

  2. #2
    Join Date
    Mar 2009
    You are confusing arrays and objects. You define "hookID" as an array, but you are trying to use it as an object. Substitute:
    var hookID = {};
    for your---
    var hookID = new Array();

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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