Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Square brackets problem

Status
Not open for further replies.

hostagency

Technical User
Feb 12, 2003
9
US
Hi - I've a square brackets problem. I'm trying to run the following function in a php file to update the value of another field. Because source variable name is products_id[2] and the destination variable is id[2][10] it keeps failing. I've tried adding elements and various combos of quotes and brackets, but it just keeps failing. The function is:

function setAttribValue() {
var selectedItem = document.cart_multi.["products_id[2]"].selectedIndex;
var selectedItemValue2 = document.cart_multi.["products_id[2]"].options[selectedItem].value2;


if (selectedItem != 0) {
document.cart_multi.elements["id[2][10]"].value = selectedItemValue2;

}
else {
document.cart_multi.elements["id[2][10]"].value = "";

}
}

<select name=&quot;products_id[2]&quot; onChange=&quot;setAttribValue()&quot;>...etc etc

<input type=&quot;hidden&quot; name=&quot;id[2][10]&quot; value=&quot;&quot;>

Any advice?

Thanks
Del
 
Thanks for the fast reply.

I just realized I was missing the elements off the first var - got it working.

Del
 
...document.cart_multi.[&quot;products_id[2]&quot;].selectedIndex;
...document.cart_multi.[&quot;products_id[2]&quot;].options

Should be-

...document.cart_multi[&quot;products_id[2]&quot;].selectedIndex;
...document.cart_multi[&quot;products_id[2]&quot;].options

No stop after _multi

~mgb
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top