Datevalue

Home Forums Quform WordPress Datevalue

This topic is: resolved
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #21083
    Nitrat
    Participant

    Hello
    How to get the value (val4) of Data field in javascript calculations? This code don’t work –
    var val4 = $(‘.iphorm_3_8’).val();

    #21091
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

    #21093
    Nitrat
    Participant

    I 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.
    #21095
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

    #21098
    Nitrat
    Participant

    Thanks, 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>

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.
Be inspired. © 2024 ThemeCatcher Ltd. 20-22 Wenlock Road, London, England, N1 7GU | Company No. 08120384 | Built with React | Privacy Policy