SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Guru
    Join Date
    Aug 2003
    Location
    CT
    Posts
    643
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    accessing array from function

    hi all, having a little issue here.

    i have the following code:

    Code:
    <script type="text/javascript">
    
    function popsizes(colorcode) {
    var BLK=new Array();
    BLK = ["2XL","3XL","4XL","5XL","LG","MD","SM","XL","XS"];
    
    elem = document.getElementById("selcolor");
    for (i=0; i<elem.options.length; i++)	{
    	sizelist = colorcode[i];
    	document.getElementById("selsize").options[i] = new Option(sizelist);
    }
    }
    
    </script>

    In an event, i'm passing in "BLK" as the colorcode param.


    This is creating my selsize select box with B, L, K, and undefined options until the for loop finishes.
    ie, its taking the passed in colorcode as a literal string, instead of referencing the array.

    Anyone have a pointer as to how i can access the arry, instead of the literal string?
    My Blog: SkeyMedia.com

  2. #2
    SitePoint Guru
    Join Date
    Aug 2003
    Location
    CT
    Posts
    643
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    got it.

    in case anyone else runs into this....


    Code:
    function popsizes(colorcode) {
    var BLK= ["2XL","3XL","4XL","5XL","LG","MD","SM","XL","XS"];
    										
    elem = document.getElementById("selcolor");
    sizelist = eval(colorcode);
    
    for (i=0; i<elem.options.length; i++)
    	{
    		document.getElementById("selsize").options[i] = new Option(sizelist[i]);
    	}
    }
    My Blog: SkeyMedia.com


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
  •