Click to See Complete Forum and Search --> : How do I use this calculation throughout the form?


DarryBoy
04-23-2003, 05:50 PM
Hi Guys

Forgive me moderators for this second post but I think maybe my first post was unclear.

I have the following calculation and want to use it to calculate the rest of the form.

<html><head>
<script>
function calc(){
var chkd;
var count = 0;
if(document.qtyFrm.c1.checked){chkd=document.qtyFrm.c1.value; count=count+1;}
if(document.qtyFrm.c2.checked){chkd=document.qtyFrm.c2.value; count=count+1;}
if(count==2){alert("Check only one, please."); return false;}
document.qtyFrm.qtyTotal.value=parseInt(document.qtyFrm.qty.value)*chkd;
}
</script>
</head><body>
<form name="qtyFrm">
<p>
<input type=text name="qty" onkeypress="calc()">
<br>
130:
<input type=checkbox name="c1" value="130" onclick="return calc()">
<br>
1300:
<input type=checkbox name="c2" value="1300" onclick="return calc()">
<br>
<input type=text name="qtyTotal">
</p>
<p>
<input type="text" name="textfield">
<br>
<input type="checkbox" name="checkbox" value="checkbox">
<br>
<input type="checkbox" name="checkbox2" value="checkbox">
<br>
<input type="text" name="textfield2">
</p>
</form></body></html>

How do I calculate the last fields and checkboxes using the above calculation?

Thank you in advance for your assistance.

Kind regards
Darryn

JackTheTripper
04-23-2003, 06:01 PM
Is this what you're looking for?

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~``

<html><head>
<script>
function calc(boxName1,boxName2){
var chkd;
var count = 0;
if(document.getElementById(boxName1).checked){chkd=document.getElementById(boxName1).value; count=count+1;}
if(document.getElementById(boxName2).checked){chkd=document.getElementById(boxName2).value; count=count+1;}
if(count==2){alert("Check only one, please."); return false;}
document.qtyFrm.qtyTotal.value=parseInt(document.qtyFrm.qty.value)*chkd;
}
</script>
</head><body>
<form name="qtyFrm">
<p>
<input type=text name="qty" onkeypress="calc('c1','c2')">
<br>
130:
<input type=checkbox name="c1" value="130" onclick="return calc('c1','c2')">
<br>
1300:
<input type=checkbox name="c2" value="1300" onclick="return calc('c1','c2')">
<br>
<input type=text name="qtyTotal">
</p>
<p>
<input type="text" name="textfield">
<br>
<input type="checkbox" name="checkbox" value="checkbox" onclick="return calc('checkbox','checkbox2')">
<br>
<input type="checkbox" name="checkbox2" value="checkbox" onclick="return calc('checkbox','checkbox2')">
<br>
<input type="text" name="textfield2">
</p>
</form></body></html>