missing ] after element list

P

Pasquale

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;
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 ***
 
L

Lee

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;
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.


--
 
L

Lee

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.


--
 
L

-Lost

Lee said:
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.
 
P

Pasquale

Lee said:
*** 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;
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; ' 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;
process.

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top