Home › Forums › Quform WordPress › Fix a NaN in jquery calculation
- This topic has 1 reply, 2 voices, and was last updated 10 years ago by
Ally.
- AuthorPosts
- May 15, 2015 at 9:18 pm #15314
johanlimm
ParticipantHello,
Your code was fix my problem, but I still stuck about the percentage calculation, last time I’m asking about Discount to apply it to the total. It works well but when I try to use Percentage, it showing up NaN. Here is the code I got so far:
<div id="form-total"></div>
<script>
jQuery(document).ready(function ($) {
var calculate = function () {
var total = 0.00;// Check the chosen option of a select menu
var val1 = $('.iphorm_1_5').val();
if (val1 == 'Paket Bronze A') {
total += 170000.00;
} else if (val1 == 'Paket Bronze B') {
total += 240000.00;
} else if (val1 == 'Paket Bronze C') {
total += 310000.00;
} else if (val1 == 'Paket Bronze D') {
total += 375000.00;
} else if (val1 == 'Paket Silver A') {
total += 315000.00;
} else if (val1 == 'Paket Silver B') {
total += 455000.00;
} else if (val1 == 'Paket Silver C') {
total += 595000.00;
} else if (val1 == 'Paket Silver D') {
total += 730000.00;
} else if (val1 == 'Paket Gold A') {
total += 550000.00;
} else if (val1 == 'Paket Gold B') {
total += 850000.00;
} else if (val1 == 'Paket Gold C') {
total += 1150000.00;
} else if (val1 == 'Paket Gold D') {
total += 1445000.00;
}// Check the Single Line Text input value
var discountCode = 'DISTR50';
var codeEntered = $('.iphorm_1_31').val();
if (discountCode == codeEntered) {
total -= $('.iphorm_1_5').val ($(this).val() * 20/100);
}// Display the result to the user
$('#form-total').text('Total: Rp. ' + total.toString().replace(/\B(?=(\d{3})+(?!\d))/g, "."));// Set the value of the hidden field
$('input[name=iphorm_1_10]').val('Rp. ' + total.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ".")); };// Calculate on page load
calculate();// Recalculate when these select menus are changed
$('.iphorm_1_5').change(calculate);// Recalculate when these text area are DISTR50
$('.iphorm_1_31').bind('keyup blur', calculate);});
</script>
On this line:
total -= $('.iphorm_1_5').val ($(this).val() * 20/100);
I’m trying to get the value from the selected dropdown menu (iphorm_1_5) and multiply it with 20 and divide it with 100 (in other words it’s 20% OFF)
I’ve also tried with this
total -= $('.iphorm_1_5').val() * 20/100;
But it’s also fail. and try to get another reference on the web but didn’t find the right one. I feel so embarrassed to ask this.
Any help would be greatly appreciated.
Kind Regards,
JohanMay 20, 2015 at 8:42 am #15332Ally
Support StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
- AuthorPosts
- You must be logged in to reply to this topic.