Results 1 to 2 of 2

Thread: Hip Hip Array....Not!

  1. #1
    Join Date
    Jul 2006
    Location
    England
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Hip Hip Array....Not!

    Hi all, I'm having a problem after a variable is carried from one page to the next. Basically I have about 20 arrays in the page the variable is carried to, I now want to call on an array which has the same name as the variable carried. for instance:



    HTML Code:
    mypage.htm?arraytouse=packA
    Note: the function GetParam() returns the value of arraytouse (above), in this case, it should return "packA"

    Code:
    var packA = new array("pack A info","pack A price","pack A postage")
    var packB = new array("pack B info","pack B price","pack B postage")
    var packC = new array("pack C info","pack C price","pack C postage")
    
    function GetParam(name)
    {
      var start=location.search.indexOf("?"+name+"=");
      if (start<0) start=location.search.indexOf("&"+name+"=");
      if (start<0) return '';
      start += name.length+2;
      var end=location.search.indexOf("&",start)-1;
      if (end<0) end=location.search.length;
      var result=location.search.substring(start,end);
      var result='';
      for(var i=start;i<=end;i++) {
        var c=location.search.charAt(i);
        result=result+(c=='+'?' ':c);
      }
      return unescape(result);
    }
    
    
    var product=GetParam('arraytouse')
    
    
    document.write(product[2])
    Which I hoped would write "pack A postage", but instead returns "undefined" due to 'product' being a string and not equal to the array PackA

    Can anyone help please??

    Thanks in advance

    Chris

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Try
    Code:
    window[product][2]
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

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