I’m currently building an order form but it seems that the method I am testing to loop through the check-boxes to see if a value is ticked or not isn’t working. What am I doing wrong? In logic it seems all right – I would appreciate any help. Thanks in advance 🙂
<script>
function order()
{
for(i=1;i<=7;i++)
{
alert(document.orderForm.order[i].checked);
}
}
</script>
<form name='orderForm'>
<p>Basic choices:</p>
<p>
<input type='checkbox' id='order1' name='order1' value='90' />
<label for="1"> Nano 1GB (£90)</label>
<br>
<input type='checkbox' id='order2' name='order2' value='155' />
<label for="2"> Nano 4GB (£155)</label>
<br>
<input type='checkbox' id='order3' name='order3' value='200' />
<label for="3"> Video 30GB (£200)</label>
<br>
<input type='checkbox' id='order4' name='order4' value='275' />
<label for="4"> Video 60GB (£275)</label>
</p>
<p>Options:</p>
<p>
<input type='checkbox' id='order5' name='order5' value='90' />
<label for="5"> Engraving (£10)</label>
<br>
<input type='checkbox' id='order6' name='order6' value='15' />
<label for="6"> Carrying case (£15)</label>
<br>
<input type='checkbox' id='order7' name='order7' value='18' />
<label for="7"> Car power adapter (£18)</label>
</p>
<p>
<input type="button" onClick="order();">
</p>
<p>Order Total</p>
<p>
<input type="text" name="orderTotal" id="orderTotal">
</p>
<p>VAT</p>
<p>
<input type="text" name="vat" id="vat">
</p>
<p>Order Total (+VAT)</p>
<p>
<input type="text" name="orderTotal_vat" id="orderTotal_vat">
</p>
</form>
document.orderForm.orderis not an array. In fact, it doesn’t exist. You need to build your id like this:Here’s a working fiddle.