Real Time Calculations?
I have searched through all of SOF and couldn't find any topic that matches my problem. I have written an HTML form that I will use PHP to process later, but I have some options in
Solution 1:
This should work how you want. Also, does not require jQuery.
functiondoMath() {
var basePrice = 15;
var baseModel = 0;
var customModel = 5;
var modelTotal;
if (document.querySelector('input[name="FIELD6"]:checked').value == "Normal Model") {
modelTotal = basePrice + customModel;
}
if (document.querySelector('input[name="FIELD6"]:checked').value == "Workshop Model") {
modelTotal = basePrice + baseModel;
}
console.log(modelTotal);
document.getElementById('total').innerHTML = '<span style="color:black">Total Price:' + modelTotal + '</span>';
}
<labelfor="FIELD6">Model Type:</label><br><inputtype="radio"id="basemodel"name="FIELD6"value="Normal Model"onclick="doMath()" />Normal Model
<br><inputtype="radio"id="workshopmodel"name="FIELD6"value="Workshop Model"onclick="doMath()" />Workshop Model
<divid="total"></div>
Solution 2:
Here is a working example of what I think you are asking for.
<labelfor="FIELD6">Model Type:</label><br><inputtype="radio"id="basemodel"name="FIELD6"value="Normal Model"checkedonclick="doMath(this)" />Normal Model<br><inputtype="radio"id="workshopmodel"name="FIELD6"value="Workshop Model"onclick="doMath(this)"data-clicked="no" />Workshop Model
<pid="total"></p><scripttype="text/javascript">functiondoMath(ele) {
var total = 15;
if($(ele).attr('id') === 'workshopmodel') {
total += 5;
}
$("#total").html('<font color="black">Total Price:</font><font color="#09ff00">' + total);
}
</script>
Post a Comment for "Real Time Calculations?"