Home › Forums › Quform WordPress › Datevalue
- This topic has 4 replies, 2 voices, and was last updated 7 years ago by Nitrat.
- AuthorPosts
- April 10, 2017 at 10:08 am #21083NitratParticipant
Hello
How to get the value (val4) of Data field in javascript calculations? This code don’t work –
var val4 = $(‘.iphorm_3_8’).val();April 10, 2017 at 4:44 pm #21091AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
April 10, 2017 at 5:09 pm #21093NitratParticipantI first tried to just bring the received variable, but it doesn’t work
I just need to get the value of datepicker and then add to it a few months<div id=”form-total”></div>
<script>
jQuery(document).ready(function ($) {
function calculate()
{
var day = $(‘.iphorm_3_8-input-day’).val(),
month = $(‘.iphorm_3_8-input-month’).val(),
year = $(‘.iphorm_3_8-input-year’).val();if (day && month && year) {
var date = new Date(year, month – 1, day);// Set the value of the hidden field
$(‘input[name=iphorm_3_3]’).val(date); };} else {
// Date not chosen
}
}// Calculate when dates changed
$(‘.iphorm_3_8-input-day, .iphorm_3_8-input-month, .iphorm_3_8-input-year’).change(calculate);
});
</script>- This reply was modified 7 years ago by Nitrat.
April 10, 2017 at 8:42 pm #21095AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
April 11, 2017 at 6:19 am #21098NitratParticipantThanks, Ally!
Everything works. This code allows you to value datapicker add the selected number of months<html>
<head>
<script src=”/js/moment.js”></script>
<script>
moment().format();
</script>
</head>
<div id=”form-total”></div><script>
jQuery(document).ready(function ($) {
function calculate()
{
var day = $(‘.iphorm_3_8-input-day’).val(),
month = $(‘.iphorm_3_8-input-month’).val(),
year = $(‘.iphorm_3_8-input-year’).val();if (day && month && year) {
var date = new Date(year, month – 1, day);// A radio button
var val3 = $(‘.iphorm_3_11’).val();
date = moment(date).add(‘months’, val3);
date = moment(date).add(‘days’, -1);
var date = moment(date).format(‘DD/MM/YYYY’);// Set the value of the hidden field
$(‘input[name=iphorm_3_3]’).val(date);} else {
// Date not chosen
}
}// Calculate when dates changed
$(‘.iphorm_3_8-input-day, .iphorm_3_8-input-month, .iphorm_3_8-input-year, .iphorm_3_11’).change(calculate);});
</script>
</html> - AuthorPosts
- You must be logged in to reply to this topic.