hans_cellc
10-04-2011, 01:36 PM
I have the following code which I want to make a selection and the value should reflect in the text box and the text box should take on that value for future calculations.
<!-- Row 13, Col 1 Order Value -->
<tr><td colspan="2" align="right">Delivery Options:
<input type="radio" name="sapo" value="35" onclick="deliveryCost('35')" /> R35 - SA Post Office
<input type="radio" name="sapo" value="80" onclick="deliveryCost('80')" /> R80 - Speed Services
<input type="radio" name="sapo" value="150" onclick="deliveryCost('150')" /> R150 - Courier Services
</td>
<!-- Row 13, Col 2 Order Value Box-->
<td colspan="1" align="left"><input style="margin-left: 60px" type="text" name="delivery" size="10" readonly="readonly" />
</td></tr>
Rough locally code:
<input type="radio" name="sapo" value="35" onclick="delivery.value=this.value" /> R35 - SA Post Office
<input type="radio" name="sapo" value="80" onclick="delivery.value=this.value" /> R80 - Speed Services
<input type="radio" name="sapo" value="150" onclick="delivery.value=this.value" /> R150 - Courier Services
hans_cellc
10-04-2011, 05:35 PM
Thanks for your response, it works perfectly.
One problem though how could I add a $ currency sign.
rangana
10-04-2011, 06:52 PM
From Kor's code:
<input type="radio" name="sapo" value="35" onclick="delivery.value='$'+this.value" /> R35 - SA Post Office
<input type="radio" name="sapo" value="80" onclick="delivery.value='$'+this.value" /> R80 - Speed Services
<input type="radio" name="sapo" value="150" onclick="delivery.value='$'+this.value" /> R150 - Courier Services
Philip M
10-04-2011, 06:52 PM
Thanks for your response, it works perfectly.
One problem though how could I add a $ currency sign.
Just put the $ sign before the radio button value - but be aware that the result is then a string value which cannot then be used in arithmetic calculations.
hans_cellc
10-04-2011, 07:06 PM
Great that works. Sorry to be a nag but it does not want to add that text box to my calculations. I also tried to parseFloat() the tDelivery but then it gives a NaN, I also tried parseInt() same Nan then With the exact code below it encapsulates the two totals printing eg: R150 R35.
All the other boxes works perfectly just the last one to add the delivery.
// Function to calculate order value
function calculateValue(orders) {
var orderValue = 0;
// Run through all the product fields
for(var i = 0; i < orders.elements.length; ++i) {
// Get the current field
var formField = orders.elements[i];
// Get the fields name
var formName = formField.name;
// Is it a "product" field?
if (formName.substring(0,4) == "prod") {
// Items price extracted from name
var itemPrice = parseFloat(formName.substring(formName.lastIndexOf("_") + 1));
// Get the Quantity
var itemQuantity = parseInt(formField.value);
// Update the OrderValue
if(itemQuantity >= 0) {
orderValue += itemQuantity * itemPrice;
}
}
}
// Display the totals
orders.totalExcl.value = "R " + orderValue.toLocaleString();
// function to calculate VAT at 15% as required and total inclusive.
function calcTotals(oValue) {
var vat = oValue * .15;
var totalIncluding = oValue + vat;
var tDelivery = orders.delivery.value;
var theTotalOrder = totalIncluding + tDelivery;
orders.vat.value = "R " + vat.toLocaleString();
orders.totalIncl.value = "R " + totalIncluding.toLocaleString();
orders.totalOrder.value = "R " + theTotalOrder.toLocaleString();
}
return calcTotals(orderValue);
}
<!-- Row 10, Col 1 Order Value exluding Vat -->
<tr><td colspan="2" align="right">Order Value Excluding Vat:</td>
<!-- Row 10, Col 2 Order Value exluding Vat Box-->
<td colspan="1" align="left">
<input name="totalExcl" type="text" style="margin-left: 60px" size="10" onfocus="this.form.elements[0].focus()" />
</td></tr>
<!-- Row 11, Col 1 Vat of 15% -->
<tr><td colspan="2" align="right">Vat calculated at 15%:</td>
<!-- Row 11, Col 2 Vat Value Box-->
<td colspan="1" align="left"><input name="vat" style="margin-left: 60px" type="text" size="10" readonly="readonly" />
</td></tr>
<!-- Row 12, Col 1 Total Order Value including Vat -->
<tr><td colspan="2" align="right">Order Value Including Vat:</td>
<!-- Row 12, Col 2 otal Order Value including Vat Box-->
<td colspan="1" align="left"><input name="totalIncl" style="margin-left: 60px" type="text" size="10" readonly="readonly" />
</td></tr>
<!-- Row 13, Col 1 Order Value -->
<tr><td colspan="2" align="right">Delivery Options:
<input type="radio" name="sapo" value="35" onclick="delivery.value='R ' + this.value" /> R35 - SA Post Office
<input type="radio" name="sapo" value="80" onclick="delivery.value='R ' + this.value" /> R80 - Speed Services
<input type="radio" name="sapo" value="150" onclick="delivery.value='R ' + this.value" /> R150 - Courier Services
</td>
<!-- Row 13, Col 2 Order Value Box-->
<td colspan="1" align="left"><input name="delivery" style="margin-left: 60px" type="text" size="10" readonly="readonly" />
</td></tr>
<!-- Row 14, Col 1 Total Order Value including Vat -->
<tr><td colspan="2" align="right"><strong>Total Order Value:</strong></td>
<!-- Row 14, Col 2 otal Order Value including Vat Box-->
<td colspan="1" align="left"><input name="totalOrder" style="margin-left: 60px" type="text" size="10" readonly="readonly" />
</td></tr>
Old Pedant
10-05-2011, 01:22 AM
*** REPOSTED ***
Answered in his repost.
Sorry, guys...didn't see this thread or would have posted here instead.