Home › Forums › Quform WordPress › Output in hidden field is not sent to email.
- This topic has 6 replies, 2 voices, and was last updated 9 years, 1 month ago by iz4atkal.
- AuthorPosts
- April 13, 2015 at 9:39 am #14949iz4atkalParticipant
Hello,
I modified the code below using my basic knowledge to display a discount depending on how many days the product is being rented for:
<div id='form-total'></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_5-input-day').val();
var sMonth = $('.iphorm_1_5-input-month').val();
var sYear = $('.iphorm_1_5-input-year').val();var eDay = $('.iphorm_1_6-input-day').val();
var eMonth = $('.iphorm_1_6-input-month').val();
var eYear = $('.iphorm_1_6-input-year').val();if (sDay !== '' && sMonth !== '' && sYear !== '' && eDay !== '' && eMonth !== '' && eYear !== '') {
// създавй две променливи, които съхраняват нови JS обект Date, но защо с - 1?
var startDate = new Date(sYear, sMonth - 1, sDay);
var endDate = new Date(eYear, eMonth - 1, eDay);var diff = daysBetween(startDate, endDate);
var fee = '';
if ( diff === 1) {
var fee = 25;
} else
if ( diff === 2) {
var fee = 50;
}
else
if ( diff === 3) {
var fee = 69;
}
else
if ( diff === 4) {
var fee = 88;
}
else
if ( diff === 5) {
var fee = 105;
}$('#form-total').text('Fee: ' + fee + '€ ');
} else {
$('#form-total').text('');
}};
// Calculate on page load
calculate();// Recalculate when these date fields are changed
$('.iphorm_1_5-input-day, .iphorm_1_5-input-month, .iphorm_1_5-input-year, .iphorm_1_6-input-day, .iphorm_1_6-input-month, .iphorm_1_6-input-year').change(calculate);});
</script>Everything works fine, but when the form is submitted, the administrator does not receive the hidden field, showing the total fee.
How do I make it so it is submitted with the rest of the form elements?
Thank you.
April 13, 2015 at 10:14 am #14950iz4atkalParticipantCorrection:
It is not the hidden field that I need to be sent, but the <div id=’form-total’></div> displaying the fee.
April 13, 2015 at 11:49 am #14954AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
April 14, 2015 at 8:47 am #14969iz4atkalParticipantHello Alli,
I have added the Hidden field, but I’m having problems passing the fee value to it.
Could you explain further where to place the two lines of code? I’ve tried:
– the ‘Default value’ line in the Hidden filed,
– at the end of the if statement in the HTML field,I have replaced the unique ID with the one of the hidden field.
Thank you for your time.
April 15, 2015 at 3:57 pm #14988iz4atkalParticipantHello again,
I tried the example in the Calculations tutorial without effect.
My attempt below:
<div id='form-total'></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_5-input-day').val();
var sMonth = $('.iphorm_1_5-input-month').val();
var sYear = $('.iphorm_1_5-input-year').val();var eDay = $('.iphorm_1_6-input-day').val();
var eMonth = $('.iphorm_1_6-input-month').val();
var eYear = $('.iphorm_1_6-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);
var fee = '';
if ( diff === 1) {
var fee = 25;
} else
if ( diff === 2) {
var fee = 50;
}
else
if ( diff === 3) {
var fee = 69;
}
else
if ( diff === 4) {
var fee = 88;
}
else
if ( diff === 5) {
var fee = 105;
}$('#form-total').text('Fee: ' + fee + '€');
$('.iphorm_1_11').val('Fee: ' + fee + '€ ');} else {
$('#form-total').text('');}
};// Calculate on page load
calculate();// Recalculate when these date fields are changed
$('.iphorm_1_5-input-day, .iphorm_1_5-input-month, .iphorm_1_5-input-year, .iphorm_1_6-input-day, .iphorm_1_6-input-month, .iphorm_1_6-input-year').change(calculate);});
</script>April 15, 2015 at 4:25 pm #14995AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
April 16, 2015 at 9:46 am #15024iz4atkalParticipantWorks great!
Thank you for your support.
- AuthorPosts
- You must be logged in to reply to this topic.