Home › Forums › Quform WordPress › Multiplying date with checkbox price
- This topic has 1 reply, 2 voices, and was last updated 6 years, 8 months ago by Ally.
- AuthorPosts
- July 26, 2017 at 8:59 am #21522pasayevParticipant
Hello,
I have a difference between check in date and checkout date. I want to multiply difference with checkbox price.
For example,
date difference is :3 days
selected checkbox: 43 $
total result: 43 x 3Here is my code:
Date difference:
———————————————————————-
<div id=’form-total2′></div>
<script>
jQuery(document).ready(function ($) {function treatAsUTC(date) {
var result = new Date(date);
result.setMinutes(result.getMinutes() – result.getTimezoneOffset());
return result;
}function daysBetween(startDate, endDate) {
var millisecondsPerDay = 24 * 60 * 60 * 1000;
return (treatAsUTC(endDate) – treatAsUTC(startDate)) / millisecondsPerDay;
}var calculate = function () {
var sDay = $(‘.iphorm_1_39-input-day’).val();
var sMonth = $(‘.iphorm_1_39-input-month’).val();
var sYear = $(‘.iphorm_1_39-input-year’).val();var eDay = $(‘.iphorm_1_40-input-day’).val();
var eMonth = $(‘.iphorm_1_40-input-month’).val();
var eYear = $(‘.iphorm_1_40-input-year’).val();if (sDay != ” && sMonth != ” && sYear != ” && eDay != ” && eMonth != ” && eYear != ”) {
var startDate = new Date(sYear, sMonth – 1, sDay);
var endDate = new Date(eYear, eMonth – 1, eDay);var diff = daysBetween(startDate, endDate);
$(‘#form-total2’).text(‘Day difference: ‘ + diff);
} else {
$(‘#form-total2’).text(”);
}};
// Calculate on page load
calculate();// Recalculate when these date fields are changed
$(‘.iphorm_1_39-input-day, .iphorm_1_39-input-month, .iphorm_1_39-input-year, .iphorm_1_40-input-day, .iphorm_1_40-input-month, .iphorm_1_40-input-year’).change(calculate);});
</script>
————————————————————-Check boxes:
————————————————————-
<div style=”font-size:20px;margin-bottom:30px;font-weight:bold” 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_16’).val();
if (val1 == ‘Student 100€’) {
total += 100.00;
} else if (val1 == ‘Academic 200€’) {
total += 200.00;
}var val3 = $(‘.iphorm_1_27:checked’).val();
if (val3 == ‘Yes’) {
total += 30.00;
} else if (val3 == ‘No’) {
total += 0.00;}
var val4 = $(‘.iphorm_1_36:checked’).val();
if (val4 == ‘Single (49€)’) {
total += 49.00;
} if (val4 == ‘Double (58€)’) {
total += 58.00;}
if (val4 == ‘Triple (86€)’) {
total += 86.00;}
var val5 = $(‘.iphorm_1_37:checked’).val();
if (val5 == ‘Single (43€)’) {
total += 43.00;
} else if (val5 == ‘Double (50€)’) {
total += 50.00;}
else if (val5 == ‘Triple (58€)’) {
total += 58.00;}
var val6 = $(‘.iphorm_1_38:checked’).val();
if (val6 == ‘Single (26€)’) {
total += 26.00;
} else if (val6 == ‘Double (38€)’) {
total += 38.00;}
else if (val6 == ‘Triple (47€)’) {
total += 47.00;}
var val6 = $(‘.iphorm_1_43:checked’).val();
if (val6 == ‘Single (43€)’) {
total += 43.00;
} else if (val6 == ”) {
total += 0.00;
}var val6 = $(‘.iphorm_1_44:checked’).val();
if (val6 == ‘Double (58€)’) {
total += 58.00;
} else if (val6 == ”) {
total += 0.00;
}var val6 = $(‘.iphorm_1_45:checked’).val();
if (val6 == ‘Triple (86€)’) {
total += 86.00;
} else if (val6 == ”) {
total += 0.00;
}var val6 = $(‘.iphorm_1_48:checked’).val();
if (val6 == ‘Single (43€)’) {
total += 43.00;
} else if (val6 == ”) {
total += 0.00;
}var val6 = $(‘.iphorm_1_49:checked’).val();
if (val6 == ‘Double (50€)’) {
total += 50.00;
} else if (val6 == ”) {
total += 0.00;
}var val6 = $(‘.iphorm_1_50:checked’).val();
if (val6 == ‘Triple (58€)’) {
total += 58.00;
} else if (val6 == ”) {
total += 0.00;
}var val6 = $(‘.iphorm_1_53:checked’).val();
if (val6 == ‘Single (26€)’) {
total += 26.00;
} else if (val6 == ”) {
total += 0.00;
}var val6 = $(‘.iphorm_1_54:checked’).val();
if (val6 == ‘Double (38€)’) {
total += 38.00;
} else if (val6 == ”) {
total += 0.00;
}var val6 = $(‘.iphorm_1_55:checked’).val();
if (val6 == ‘Triple (47€)’) {
total += 47.00;
} else if (val6 == ”) {
total += 0.00;
}// Display the result to the user
$(‘#form-total’).text(‘Total Amount: ‘ + total + ‘ €’);// Set the value of the hidden field
$(‘input[name=iphorm_1_56]’).val(‘$’ + total);
};// Calculate on page load
calculate();// Recalculate when these select menus are changed
$(‘.iphorm_1_16, .iphorm_1_32, .iphorm_1_43, .iphorm_1_44, .iphorm_1_45, .iphorm_1_48, .iphorm_1_49, .iphorm_1_50, .iphorm_1_53, .iphorm_1_54, .iphorm_1_55, iphorm_1_56’).change(calculate);// Recalculate when these checkboxes/radio buttons are clicked
$(‘.iphorm_1_26, .iphorm_1_27, .iphorm_1_36, .iphorm_1_37, .iphorm_1_38, .iphorm_1_43, .iphorm_1_44, .iphorm_1_45, .iphorm_1_48, .iphorm_1_49, .iphorm_1_50, .iphorm_1_53, .iphorm_1_54, .iphorm_1_55, iphorm_1_56’).click(calculate);// Recalculate when these text input fields are changed
$(‘.iphorm_1_7’).blur(calculate);
});
</script>
———————————————————————————-July 31, 2017 at 4:10 pm #21555AllySupport 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.