...

View Full Version : Need to multiply a checkbox value.



hubbni
06-26-2006, 05:01 PM
I am stuck in a rut with javascript. Here is the page that I am working on:

https://www.puc.edu/PUC/newsevents/graduation/2006/order_form.shtml

It is for an order form, which was working great. I had it so the user could select which DVD's they wanted to order, and it would total the amout of each DVD by what checkbox they select. But now, I realized I need to have a field for number of orders per DVD. Which throws in a whole new problem. I now need to have the DVD total come up in the total box, but if someone enters that they need 5 DVD, I need the total field to multiply by the number entered. I am still new to this, so if anyone could look at my code, and give me a few times it would be much appreciated!

vwphillips
06-26-2006, 06:50 PM
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<title></title>
</head>

<body>
<script language="JavaScript" type="text/javascript">
/*<![CDATA[*/
function Cal(obj){
var frm=obj.form;
if (!window[frm.name+'Ary']&&obj.type=='text'){ window[frm.name+'Ary']=[]; }
if (!window[obj.name+'Set']&&obj.type=='text'){ window[obj.name+'Set']==true; window[frm.name+'Ary'].push(obj); }
if (!window[frm.name+'Ary']){ return; }
var ary=window[frm.name+'Ary'];
var eles=frm.elements;
var val=0
for (var zxc0=0;zxc0<eles.length;zxc0++){
for (var zxc1=0;zxc1<ary.length;zxc1++){
if (eles[zxc0]==ary[zxc1]){
if (eles[zxc0-1].checked&&eles[zxc0].value.length>0&&!isNaN(eles[zxc0].value)){
val+=eles[zxc0-1].value*eles[zxc0].value;
}
}
}
}
frm.hiddentotal.value=val;
}


/*]]>*/
</script>
<form name="AnyName" >
<table>

<tr>
<td colspan="2"><p><span class="sans11"><strong><font color="#FF0000" size="2"><strong>*</strong></font>Please select which DVDs you would like to order: </strong></span></p>
<p><span class="sans11">Full Weekend Packages:</span> <span class="sans11"><font size="2"><B><BR>
</B></font></span>
<input name="Consecration, Baccalaureate, and Commencement" type="checkbox" id="Consecration, Baccalaureate, and Commencement" value=50.00 onclick="Cal(this);" >
<span class="sans11">Consecration, Baccalaureate, and Commencement ($50) x
<input name="Consecration, Baccalaureate, and Commencement Quantity" type="text" class="boxcolor" id="Consecration, Baccalaureate, and Commencement Quantity" size="2" onblur="Cal(this);">

</span> <span class="sans11"><font size="2"><B><BR>
</B></font></span>
<input name="Consecration, Baccalaureate, Nurses Pinning and Commencement" type="checkbox" id="Consecration, Baccalaureate, Nurses Pinning and Commencement" value=65.00 onclick="Cal(this);" >
<span class="sans11">Consecration, Baccalaureate, Nurses' Pinning and Commencement ($65) </span> <span class="sans11">x
<input name="Consecration, Baccalaureate, Nurses Pinning and Commencement Quantity" type="text" class="boxcolor" id="Consecration, Baccalaureate, Nurses Pinning and Commencement Quantity" size="2" onblur="Cal(this);">
</span></p>
<p><span class="sans11">Single Event:</span> <span class="sans11"><font size="2"><B><BR>

</B></font></span>
<input name="Baccalaureate" type="checkbox" id="Baccalaureate" value=20.00 onclick="Cal(this);" >
<span class="sans11">Baccalaureate DVD ($20) x
<input name="Baccalaureate Quantity" type="text" class="boxcolor" id="Baccalaureate Quantity" size="2" onblur="Cal(this);" >
</span> <span class="sans11"><font size="2"><B><BR>
</B></font></span>
<input name="Consecration" type="checkbox" id="Consecration" value=20.00 onclick="Cal(this);" >
<span class="sans11">Consecration DVD ($20) x
<input name="Consecration Quantity" type="text" class="boxcolor" id="Consecration Quantity" size="2" onblur="Cal(this);">

</span> <span class="sans11"><font size="2"><B><BR>
</B></font></span>
<input name="Commencement" type="checkbox" id="Commencement" value=20.00 onclick="Cal(this);" >
<span class="sans11">Commencement DVD ($20) x
<input name="Commencement Quantity" type="text" class="boxcolor" id="Commencement Quantity" size="2" onblur="Cal(this);">
<font size="2"><b><br>
</b></font></span>
<input name="Nurses Pinning" type="checkbox" id="Nurses Pinning" value=20.00 onclick="Cal(this);" >
<span class="sans11">Nurses' Pinning DVD ($20) x
<input name="Nurses Pinning Quantity" type="text" class="boxcolor" id="Nurses Pinning Quantity" size="2" onblur="Cal(this);" >

<font size="2"><b><br>
</b></font><font size="2"><b><br>
</b></font></span></p>
<input type="text" name="hiddentotal" value=0>
<input type="hidden" name="hiddenpriorradio" value=0>
</td>
</tr>
</table>
</form>
</body>

</html>

hubbni
06-26-2006, 07:12 PM
Seems like that code is a little off. See here:

https://www.puc.edu/PUC/newsevents/graduation/2006/order_form1.shtml

It seems to act sort of speratic, and does not do that math correcly. Did I do something wrong?

vwphillips
06-27-2006, 08:51 AM
your page tested and works fine, calulating on the onblur event

+ thank you is good

hubbni
06-28-2006, 05:24 PM
Still not working. The calculations are wrong. It seems that it is double the number that it is suppose to be. Also, if you check back between the quantaty fields, it keeps adding up the total, for no reason! Is there a way to correct this?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum