Forum Moderators: open

Message Too Old, No Replies

Using js form variable in a link

javascript form in link

         

rsmarsha

11:12 am on Jul 3, 2007 (gmt 0)

10+ Year Member



Hi,

This is probably a simple problem, but i can't seem to get it working.

I have a link which is created with a php while loop.

Each loop gives some product info, a quantity box and an add link.

I want the link quantity value to change when a the text field next to it is changed.

<input type="text" name="loopQty" id="loopQty" value="<?php echo $cr2['qty'];?>" class="textbox" size="3">
<a href="cart.php?xCmd=add&xProd=<?php echo $cr2['productID'];?>&qty<?php echo $cr2['productID'];?>=changewithfield">{labels.cart.addToCartLink}</a>

It's the section =changewithfield near the link end that needs to change with the input field.

Any help much appreciated. :)

vincevincevince

11:24 am on Jul 3, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




<input type="text" name="loopQty" id="loopQty" value="<?php echo $cr2['qty'];?>" class="textbox" size="3">
<a href="javascript://" onClick="top.location='cart.php?xCmd=add&xProd=<?php echo $cr2['productID'];?>&qty<?php echo $cr2['productID'];?>='+document.getElementById('loopQty').value">{labels.cart.addToCartLink}</a>

rsmarsha

12:04 pm on Jul 3, 2007 (gmt 0)

10+ Year Member



Thanks, works a treat. :)

I amended it to work with each item in the list.

<input type="text" name="loopQty<?php echo $cr2['productID'];?>" id="loopQty<?php echo $cr2['productID'];?>" value="<?php echo $cr2['qty'];?>" class="textbox" size="3">
<a href="javascript://" onClick="top.location='cart.php?xCmd=add&xProd=<?php echo $cr2['productID'];?>&qty<?php echo $cr2['productID'];?>='+document.getElementById('loopQty<?php echo $cr2['productID'];?>').value">{labels.cart.addToCartLink}</a>

Thanks again for the help.