missing ] after element list - Javascript

This is a discussion on missing ] after element list - Javascript ; I am attempting to populate a few select drop down menus from the selection of the first drop down. I am using ajax to submit data via a PHP GET and from the response populate the other drop down menus. ...

+ Reply to Thread
Results 1 to 5 of 5

missing ] after element list

  1. Default missing ] after element list

    I am attempting to populate a few select drop down menus from the
    selection of the first drop down. I am using ajax to submit data via a
    PHP GET and from the response populate the other drop down menus.

    I figured out how to get it to do so for more than one drop down, but I
    am getting the following error below. This was working fine until I
    tried to populate more than one other drop down menu. Any idea why the
    SELECT object isn't being passed? It seems so close.

    Thanks,
    Pasquale


    *** begin error ***
    missing ] after element list
    GetInfo([object HTMLSelectElement],1,"Color") Line 82
    -----------------|
    *** end error ***

    *** begin JavaScript snip ***
    var attr;
    var attrarray = new Array (
    'Color','Type'
    );


    function InfoLoop (sel,selset) {
    for (var i = 0; i < attrarray.length; i++) {
    attr = attrarray[i];
    setTimeout('GetInfo('+sel+','+selset+',"'+attr+'")',2000); //Line 82
    }
    }
    *** end JavaScript snip ***

    *** begin HTML snip ***
    <SELECT id="Collection_1" name="Collection_1" size="1"
    onChange="InfoLoop(this,1)">
    *** end HTML snip ***

  2. Default Re: missing ] after element list

    Pasquale said:
    >
    >I am attempting to populate a few select drop down menus from the
    >selection of the first drop down. I am using ajax to submit data via a
    >PHP GET and from the response populate the other drop down menus.
    >
    >I figured out how to get it to do so for more than one drop down, but I
    >am getting the following error below. This was working fine until I
    >tried to populate more than one other drop down menu. Any idea why the
    >SELECT object isn't being passed? It seems so close.
    >
    >Thanks,
    >Pasquale
    >
    >
    >*** begin error ***
    >missing ] after element list
    >GetInfo([object HTMLSelectElement],1,"Color") Line 82
    >-----------------|
    >*** end error ***
    >
    >*** begin JavaScript snip ***
    >var attr;
    >var attrarray = new Array (
    > 'Color','Type'
    >);
    >
    >
    >function InfoLoop (sel,selset) {
    > for (var i = 0; i < attrarray.length; i++) {
    > attr = attrarray[i];
    > setTimeout('GetInfo('+sel+','+selset+',"'+attr+'")',2000); //Line 82
    > }
    >}
    >*** end JavaScript snip ***
    >
    >*** begin HTML snip ***
    > <SELECT id="Collection_1" name="Collection_1" size="1"
    >onChange="InfoLoop(this,1)">
    >*** end HTML snip ***


    You're passing a reference to the Select object into infoLoop(),
    and inside that function you're using that argument in a string
    concatination. In order to do that, Javascript uses the value
    of the Select object's toString() method, which seems to be
    "[object HTMLSelectElement]".

    Instead of passing a reference to the Select, pass its id value,
    which can safely be concatinated into a string. You'll also
    have to make changes to infoLoop() and GetInfo() so they treat
    the value correctly.


    --


  3. Default Re: missing ] after element list

    Lee said:

    >You're passing a reference to the Select object into infoLoop(),
    >and inside that function you're using that argument in a string
    >concatination. In order to do that, Javascript uses the value
    >of the Select object's toString() method, which seems to be
    >"[object HTMLSelectElement]".
    >
    >Instead of passing a reference to the Select, pass its id value,
    >which can safely be concatinated into a string. You'll also
    >have to make changes to infoLoop() and GetInfo() so they treat
    >the value correctly.


    I find it really annoying that, after all these years of
    using the word, my fingers still haven't learned to spell
    "concatenate" correctly.


    --


  4. Default Re: missing ] after element list

    Lee wrote:
    > Lee said:
    >
    >> You're passing a reference to the Select object into infoLoop(),
    >> and inside that function you're using that argument in a string
    >> concatination. In order to do that, Javascript uses the value
    >> of the Select object's toString() method, which seems to be
    >> "[object HTMLSelectElement]".
    >>
    >> Instead of passing a reference to the Select, pass its id value,
    >> which can safely be concatinated into a string. You'll also
    >> have to make changes to infoLoop() and GetInfo() so they treat
    >> the value correctly.

    >
    > I find it really annoying that, after all these years of
    > using the word, my fingers still haven't learned to spell
    > "concatenate" correctly.


    Hahaha. I thank the Mozilla gods everyday for Thunderbirds "spell check
    as you type" feature.

    --
    -Lost
    Remove the extra words to reply by e-mail. Don't e-mail me. I am
    kidding. No I am not.

  5. Default Re: missing ] after element list

    Lee wrote:
    >>
    >> *** begin JavaScript snip ***
    >> var attr;
    >> var attrarray = new Array (
    >> 'Color','Type'
    >> );
    >>
    >>
    >> function InfoLoop (sel,selset) {
    >> for (var i = 0; i < attrarray.length; i++) {
    >> attr = attrarray[i];
    >> setTimeout('GetInfo('+sel+','+selset+',"'+attr+'")',2000); //Line 82
    >> }
    >> }
    >> *** end JavaScript snip ***
    >>
    >> *** begin HTML snip ***
    >> <SELECT id="Collection_1" name="Collection_1" size="1"
    >> onChange="InfoLoop(this,1)">
    >> *** end HTML snip ***

    >
    > You're passing a reference to the Select object into infoLoop(),
    > and inside that function you're using that argument in a string
    > concatination. In order to do that, Javascript uses the value
    > of the Select object's toString() method, which seems to be
    > "[object HTMLSelectElement]".
    >
    > Instead of passing a reference to the Select, pass its id value,
    > which can safely be concatinated into a string. You'll also
    > have to make changes to infoLoop() and GetInfo() so they treat
    > the value correctly.
    >


    Thanks! That is fixed, but now the ' attr = attrarray[i]; ' is
    processing before the return of the PHP data. So the options are put
    into the second of the attributes drop down instead of the first.

    Thinking about, it would probably be better to wait until
    the return of the PHP data is done and then have attr = attrarray[i];
    process.

    But out of curiousity, can I setTimeout to ' attr = attrarray[i]; ' to
    have it pause for a second?


    >


+ Reply to Thread

Similar Threads

  1. XmlReader error Root Element is missing
    By Application Development in forum CSharp
    Replies: 3
    Last Post: 11-22-2007, 11:15 AM
  2. Missing graphic links: XML structure element, not in layout
    By Application Development in forum Adobe Indesign
    Replies: 1
    Last Post: 08-03-2007, 03:02 PM
  3. WSE910 and 'Root element is missing.'
    By Application Development in forum DOTNET
    Replies: 1
    Last Post: 10-20-2006, 06:12 AM
  4. WSE910 and 'Root element is missing.'
    By Application Development in forum Inetserver
    Replies: 1
    Last Post: 10-20-2006, 06:12 AM
  5. Missing required element in serialized XML
    By Application Development in forum DOTNET
    Replies: 3
    Last Post: 05-16-2006, 05:11 AM