Click to See Complete Forum and Search --> : can't pass value to form


travisb
10-03-2003, 04:27 PM
I am trying to pass a vaule to a text field in a form and am having trouble doing so. I have images with javascript like this

<img src="/images/add.jpg" width="19" height="19" alt="Add Your Selection" border="0" onClick="parent.passclr(clr_array = new Array('5233-12'));">
which calls this function

function passclr(clr_array) {
document.order_form.id[2].value = clr_array[0];
}

and this form

<form name="order_form" action="http://www.mysite.com/product_info.php/action/add_product" method="post">
Product:<br />
<input type="text" size="15" name="pro" value=" " /><br />
Model #:<br />
<input type="text" size="5" name="mod" value=" " /><input type="text" size="5" name="products_id" value=" " /><br />
Upholstery #:<br />
<input type="text" size="15" name="id[2]" value=" " /><br />
Starting Price:<br />
<input type="text" size="15" name="spr" value=" " /><br />
Upholstery Price:<br />
<input type="text" size="15" name="upr" value=" " /><br />
Total:<br />
<input type="text" size="15" name="tot" value=" " /><br /><br />
<input type="image" src="/images/add_to_cart.jpg" width="80" height="20" alt="Add To Cart" border="0">
</form>


The problem is with the [] in the name of the field id[2]. If I change the name the script works fine, but I have to have it called id[2] because of the shopping cart program I am using. Any ideas on how to get the value to the text field?

AdamBrill
10-03-2003, 04:31 PM
This should work:

document.formname.elements["id[2]"].value

travisb
10-03-2003, 04:33 PM
I am not sure if this what you mean. It does not work.

document.order_form.["id[2]"].value = clr_array[0];

AdamBrill
10-03-2003, 04:41 PM
You didn't look at what I had... :p

Try this:

document.order_form.elements["id[2]"].value = clr_array[0];

travisb
10-03-2003, 04:45 PM
Ok, thanks! It is working now.

AdamBrill
10-03-2003, 04:48 PM
lol, no problem. ;)