PDA

View Full Version : Forms with tickboxes


stewea99
08-27-2002, 02:09 PM
How do you assign values to tickboxes, so when selected they put a figure in a totals box at the bottom of a form?

E.g. Tickbox1 selected, its value is 10, tickbox2 selected its value is 15, after tickbox2 is checked the value in the totals box is 25.

Any suggestions

Thanks

scoutt
08-27-2002, 02:54 PM
something like this

http://www.a1javascripts.com/utilities/costcalculator/costcalculator.html

it has teh same concept you want, just have to redo part of it so you can use checkboxes instead.

kdjoergensen
08-30-2002, 01:04 PM
<html>
<body>
<form name='valBox'>
<b>5: <input type='checkbox' name='dlrs' value=5 onclick='add(this,this.form)'></b><br>
<b>10: <input type='checkbox' name='dlrs' value=10 onclick='add(this,this.form)'></b><br>
<b>15: <input type='checkbox' name='dlrs' value=15 onclick='add(this,this.form)'></b><br>
<b>20: <input type='checkbox' name='dlrs' value=20 onclick='add(this,this.form)'></b><br>
<br><br>
<b>Total:</b>&nbsp;<input type="text" size=30 value=0 name='total'>
</form>
<script language='javascript'>
function add(amount,formName){
formName.total.value = (amount.checked) ?
parseInt(formName.total.value) + parseInt(amount.value) :
parseInt(formName.total.value) - parseInt(amount.value);
}
</script>

</body>
</html>