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.
...
-
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 ***
-
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.
--
-
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.
--
-
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.
-
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?
>
Similar Threads
-
By Application Development in forum CSharp
Replies: 3
Last Post: 11-22-2007, 11:15 AM
-
By Application Development in forum Adobe Indesign
Replies: 1
Last Post: 08-03-2007, 03:02 PM
-
By Application Development in forum DOTNET
Replies: 1
Last Post: 10-20-2006, 06:12 AM
-
By Application Development in forum Inetserver
Replies: 1
Last Post: 10-20-2006, 06:12 AM
-
By Application Development in forum DOTNET
Replies: 3
Last Post: 05-16-2006, 05:11 AM