MissNightAngel
10-31-2002, 07:26 PM
I am trying to make an order form that will calculate the $ total while the person is filling out the form. The form contains a "qty" box and several check boxes that need to be figured into the total. The function script I have is not working when I add the check boxes but it will work if I use the input=text boxes like the qty box. I have tried using onClick instead of onBlur for the checkboxes and it didn't help. How can I change the function script to include the check boxes in the total?
<script>
function calculate(what) {
for (var i=1,answer=0;i<5;i++)
answer += what.elements['txtSold' + i].value - 0;
what.txtSoldTotal.value = answer;
}
function calculateGrand(grand) {
for (var i=1,answer=0;i<5;i++)
answer += grand.elements['txtGrand' + i].value - 0;
grand.txtGrandTotal.value = answer;
}
function itemTotal(item){
doc = "document.frmOrder";
eval ("document.frmOrder.txtGrand"+item+".value = document.frmOrder.txtCost" + item +".value * document.frmOrder.txtSold"+ item + ".value");
}
</script>
<form>
<input type="hidden" name="txtCost1" value="268.95">
<input type="hidden" name="txtCost2" value="99.95">
<input type="hidden" name="txtCost3" value="99.95">
<input type="hidden" name="txtCost4" value="99.95">
<input type="hidden" name="txtCost5" value="99.95">
<input type="hidden" name="txtCost6" value="49.95">
<table border=1 cellpadding=1 cellspacing=0 width="65%" align=center valign=middle>
<TR BGCOLOR="#666666"><td width="100%" align=center valign=middle> ITEMS:</td></tr>
<TR><TD align=center valign=middle>
Style 1 -- 35 Cigars
Qty<input type=text size=4 name=cigarbox1qty value="" onBlur="calculate(this.form); itemTotal('1'); calculateGrand(this.form);">
<BR>
<input type=checkbox name=style1color value="black">Black
<input type=checkbox name=style1color value="brown" onBlur="calculate(this.form); itemTotal('2'); calculateGrand(this.form);">Brown
<input type=checkbox name=style1color value="blue" onBlur="calculate(this.form); itemTotal('3'); calculateGrand(this.form);">Blue
<input type=checkbox name=style1color value="red" onBlur="calculate(this.form); itemTotal('4'); calculateGrand(this.form);">Red
<input type=checkbox name=style1color value="green" onBlur="calculate(this.form); itemTotal('5'); calculateGrand(this.form);">Green<BR>
<input type=checkbox name=style1color value="clear">Clear with Red Cedar
<input type=checkbox name=style1color value="addcedar" onBlur="calculate(this.form); itemTotal('6'); calculateGrand(this.form);">Add Red Cedar Lining
<TR><TD align=center valign=middle><input type="hidden" name="txtSoldTotal" size="6" value="" >
Subtotal:$<input type="text" size="9" name="txtGrandTotal" value="">
</TABLE><center>
<input type=submit name=submit value="Send Order" STYLE="background:FFCC99">
<input type=reset name=reset value="Clear Form" STYLE="background:FFCC99">
</FORM>
:( :confused: :(
<script>
function calculate(what) {
for (var i=1,answer=0;i<5;i++)
answer += what.elements['txtSold' + i].value - 0;
what.txtSoldTotal.value = answer;
}
function calculateGrand(grand) {
for (var i=1,answer=0;i<5;i++)
answer += grand.elements['txtGrand' + i].value - 0;
grand.txtGrandTotal.value = answer;
}
function itemTotal(item){
doc = "document.frmOrder";
eval ("document.frmOrder.txtGrand"+item+".value = document.frmOrder.txtCost" + item +".value * document.frmOrder.txtSold"+ item + ".value");
}
</script>
<form>
<input type="hidden" name="txtCost1" value="268.95">
<input type="hidden" name="txtCost2" value="99.95">
<input type="hidden" name="txtCost3" value="99.95">
<input type="hidden" name="txtCost4" value="99.95">
<input type="hidden" name="txtCost5" value="99.95">
<input type="hidden" name="txtCost6" value="49.95">
<table border=1 cellpadding=1 cellspacing=0 width="65%" align=center valign=middle>
<TR BGCOLOR="#666666"><td width="100%" align=center valign=middle> ITEMS:</td></tr>
<TR><TD align=center valign=middle>
Style 1 -- 35 Cigars
Qty<input type=text size=4 name=cigarbox1qty value="" onBlur="calculate(this.form); itemTotal('1'); calculateGrand(this.form);">
<BR>
<input type=checkbox name=style1color value="black">Black
<input type=checkbox name=style1color value="brown" onBlur="calculate(this.form); itemTotal('2'); calculateGrand(this.form);">Brown
<input type=checkbox name=style1color value="blue" onBlur="calculate(this.form); itemTotal('3'); calculateGrand(this.form);">Blue
<input type=checkbox name=style1color value="red" onBlur="calculate(this.form); itemTotal('4'); calculateGrand(this.form);">Red
<input type=checkbox name=style1color value="green" onBlur="calculate(this.form); itemTotal('5'); calculateGrand(this.form);">Green<BR>
<input type=checkbox name=style1color value="clear">Clear with Red Cedar
<input type=checkbox name=style1color value="addcedar" onBlur="calculate(this.form); itemTotal('6'); calculateGrand(this.form);">Add Red Cedar Lining
<TR><TD align=center valign=middle><input type="hidden" name="txtSoldTotal" size="6" value="" >
Subtotal:$<input type="text" size="9" name="txtGrandTotal" value="">
</TABLE><center>
<input type=submit name=submit value="Send Order" STYLE="background:FFCC99">
<input type=reset name=reset value="Clear Form" STYLE="background:FFCC99">
</FORM>
:( :confused: :(