Another problem involving format-for-PHP Javascript functions and form elements

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Phil Powell

    #1

    Another problem involving format-for-PHP Javascript functions and form elements

    Code:
    function populateWithPics(folder) {
    if (folder.value != '') {
    monthIndex = folder.name.substring(folder.name.indexOf("'") + 1,
    folder.name.indexOf('\]') - 1);
    indexArray = folder.value.split('|');
    index = indexArray[0];
    if (!isNaN(index)) {
    for (i = 0; i < picsArray[index].length; i++) {
    document.calendarPicForm.elements['pics\[' + monthIndex +
    '\]'].options[i + 2].value = picsArray[index][i];
    document.calendarPicForm.elements['pics\[' + monthIndex +
    '\]'].options[i + 2].text = picsArray[index][i];
    }
    }
    }
    }
    The preceeding code is going to populate a dropdown named pics['0'] or
    pics['5'] or pics['digit between 0 and 11'] with contents found in
    picsArray[0] or picsArray[5], etc.

    However upon attempt to do so I am getting the following error:

    "document.calen darPicForm.elem ents['....'] is null or not an object"

    Here is the script for the dropdown (an example, since there are 12 of
    them to choose from):

    Code:
    <select name=pics[2]>
    <option value="">
    Choose a picture to display for the month of Mars:
    </option>
    <option value="">-------------------------------------------</option>
    </select>
    And picsArray is a 2-dim TCL-generated server-side array:

    Code:
    <script type="text/javascript">
    <!--
    picsArray[0] = new Array(7);
    
    picsArray[0][0] = '/images/bands/Crimson_Moonlight.jpg';
    
    picsArray[0][1] = '/images/bands/Crimson_Thorn.jpg';
    
    picsArray[0][2] = '/images/bands/Extol.JPG';
    
    picsArray[0][3] = '/images/bands/Lengsel.jpg';
    
    picsArray[0][4] = '/images/bands/Vaakevandring.jpg';
    
    picsArray[0][5] = '/images/bands/Zane_Matthews_04.jpg';
    
    picsArray[0][6] = '/images/bands/vaakevandring2.jpg';
    
    //-->
    </script>
    Bottom line: I want to populate a corresponding dropdown with a
    corresponding 2-dim array upon selecting something from one of 12
    dropdowns. The function fails due to the structure of of the form
    element, so I am not sure what to do at this point, so I need help
    again.

    Thanx
    Phil
  • Michael Winter

    #2
    Re: Another problem involving format-for-PHP Javascript functions and form elements

    On 18 Apr 2004 20:40:00 -0700, Phil Powell <soazine@erols. com> wrote:

    [snip]
    [color=blue]
    > The preceeding code is going to populate a dropdown named pics['0'] or
    > pics['5'] or pics['digit between 0 and 11'] with contents found in
    > picsArray[0] or picsArray[5], etc.
    >
    > However upon attempt to do so I am getting the following error:
    >
    > "document.calen darPicForm.elem ents['....'] is null or not an object"
    >
    > Here is the script for the dropdown (an example, since there are 12 of
    > them to choose from):
    >
    > [Code]
    > <select name=pics[2]>[/color]

    This is most likely to be the source of the problem. Only a combination of
    letters, numbers, colons (:), underscores (_), periods (.), and hyphens
    (-). Any other character requires the entire attribute value to be quoted.
    I expect that if you check the document tree, that SELECT element has a
    name attribute of "pics".

    [snip]
    [color=blue]
    > <script type="text/javascript">
    > <!--[/color]

    Hiding scripts is an obsolete practice. Remove the SGML comment delimiters.
    [color=blue]
    > picsArray[0] = new Array(7);
    >
    > picsArray[0][0] = '/images/bands/Crimson_Moonlig ht.jpg';
    >
    > picsArray[0][1] = '/images/bands/Crimson_Thorn.j pg';
    >
    > picsArray[0][2] = '/images/bands/Extol.JPG';
    >
    > picsArray[0][3] = '/images/bands/Lengsel.jpg';
    >
    > picsArray[0][4] = '/images/bands/Vaakevandring.j pg';
    >
    > picsArray[0][5] = '/images/bands/Zane_Matthews_0 4.jpg';
    >
    > picsArray[0][6] = '/images/bands/vaakevandring2. jpg';[/color]

    [snip]

    Look into using array literals. You could write the above with

    picsArray = [
    [ '/images/bands/Crimson_Moonlig ht.jpg',
    '/images/bands/Crimson_Thorn.j pg',
    '/images/bands/Extol.JPG',
    '/images/bands/Lengsel.jpg',
    '/images/bands/Vaakevandring.j pg',
    '/images/bands/Zane_Matthews_0 4.jpg',
    '/images/bands/vaakevandring2. jpg' ],
    [ /* picsArray[ 1 ] */ ]];

    Hope that helps,
    Mike

    --
    Michael Winter
    M.Winter@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)

    Comment

    Working...