Jump to content

Autocalculation issue using javascript


dp2020

Recommended Posts

<script type="text/javascript"> //function to calculate price for ring1
function calculate_price_ring1()
{
if(price1.value=="" || price1.value!=parseFloat(price1.value)) 
{
price1.value=0;
}

if(totaldiamondprice1.value=="" || totaldiamondprice1.value!=parseFloat(totaldiamondprice1.value)) 
{
totaldiamondprice1.value=0;
}

totalpriceforring1.value=0;

totalpriceforring1.value=parseFloat(totalpriceforring1.value);

totalpriceforring1.value=parseFloat(totalpriceforring1.value)+parseFloat(price1.value)+parseFloat(totaldiamondprice1.value);
return totalpriceforring1.value;
}
</script>
<script type="text/javascript"> //function to calculate price for ring2
function calculate_price_ring2()
{
if(price2.value=="" || price2.value!=parseFloat(price2.value)) 
{
price2.value=0;
}

if(totaldiamondprice2.value=="" || totaldiamondprice2.value!=parseFloat(totaldiamondprice2.value)) 
{
totaldiamondprice2.value=0;
}

totalpriceforring2.value=0;

totalpriceforring2.value=parseFloat(totalpriceforring2.value);

totalpriceforring2.value=parseFloat(totalpriceforring2.value)+parseFloat(price2.value)+parseFloat(totaldiamondprice2.value);
return totalpriceforring2.value;
}
</script>

<script type="text/javascript"> //function to calculate price for ring1 & ring2
function calculate_totalprice()
{
totalringscost.value = calculate_price_ring1() + calculate_price_ring2();
}
return totalringscost.value;
</script>

 

<div>
				<label for="price1">Price (?)</label> 
				<input type="text" id="price1" name="price1" value = '<?php echo htmlentities($price1) ?>'onchange = "calculate_price_ring1()">
			</div>


			<div>
				<label for="totaldiamondprice1">Total Diamond Price (?)</label> 
				<input type="text" id="totaldiamondprice1" name="totaldiamondprice1" value = '<?php echo htmlentities($totaldiamondprice1) ?>' onchange = "calculate_price_ring1()"maxlength="20">
			</div>

<div>
				<label for="price2">Price (?)</label> 
				<input type="text" id="price2" name="price2" value = '<?php echo htmlentities($price2) ?>'onchange = "calculate_price_ring2()">
			</div>

<div text align='right'>
			<h2 text align='right'>Total Price for Ring 1 (?) </h2>
				<input type="text" id="totalpriceforring1" name="totalpriceforring1" onkeyup="calculate_price_ring1()" onchange="calculate_totalprice()">
			</div>


<div>
				<label for="totaldiamondprice2">Total Diamond Price (?)</label> 
				<input type="text" id="totaldiamondprice2" name="totaldiamondprice2" value = '<?php echo htmlentities($totaldiamondprice2) ?>'onchange = "calculate_price_ring2()" maxlength="20">
			</div>

<div text align='right'>
			<h2 text align='right'>Total Price for Ring 2 (?) </h2>
				<input type="text" id="totalpriceforring2" name="totalpriceforring2" onkeyup="calculate_price_ring2()" onchange="calculate_totalprice()" maxlength="5">
			</div>


<div text align='right'>
					<h4 text align='right'>Total Rings (1 + 2) ? </h4>
					<input type="text" id="totalringscost" name="totalringscost" onkeyup="calculate_totalprice()">
				</div>

 

 

How do i get the calculated price from both the totalpriceforring1 and totalpriceforring2 txt boxes into totalringscost txt box using javascript?

 

The code above doesn't seem to help. Please could you sort this or advice what could be done?

 

Any help is much appreciated

Link to comment
https://forums.phpfreaks.com/topic/267555-autocalculation-issue-using-javascript/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.