Hi everyone.
I'm trying to create a shopping cart (with PHP) and it's all going pretty good. Except I'm trying to make a quantity drop down menu which when you change the quantity the total field is updated... I had it working for one, but when I tried to implement it into a for loop (so that when there are more than one item on the page they work separately) nothing happens.
Here is my javascript
and here is a section of my PHP inside the for loop, $price comes from a database (and works) and $i is just the loop count number
Any questions just ask! Thanks in advance!
I'm trying to create a shopping cart (with PHP) and it's all going pretty good. Except I'm trying to make a quantity drop down menu which when you change the quantity the total field is updated... I had it working for one, but when I tried to implement it into a for loop (so that when there are more than one item on the page they work separately) nothing happens.
Here is my javascript
Code:
<script type='text/javascript'>
function totalise(price,total)
{
var qty = window.document.getElementById('qty').value;
var result = total;
result.value = price * qty;
}
</script>
Code:
<td>
<select id='qty' onChange=totalise($price,total{$i})>
<option value='0'>0</option>
<option value='1'>1</option>
<option value='2'>2</option>
<option value='3'>3</option>
<option value='4'>4</option>
<option value='5'>5</option>
<option value='6'>6</option>
</select>
</td>
<td>$ <input id='total{$i}' type='text' readonly /></td>
Comment