1

The code below is the function of the jquery

$(function() {
    $(".firstcal").datepicker({
        dateFormat: "dd/mm/yy",
        onSelect: function(dateText, instance) {
            date = $.datepicker.parseDate(instance.settings.dateFormat, dateText, instance.settings);
            date.setMonth(date.getMonth() + 6);
            $(".secondcal").datepicker("setDate", date);
        }
    });
    $(".secondcal").datepicker({
        dateFormat: "dd/mm/yy"
    }).attr("disabled", 'disabled');
});

What i am trying to do is that when user choose 1 date from the first datepicker, it will update(+6 month) on 2nd datepicker , but unable to change the date anymore.(only first datepicker able to change) and i need to insert it to database , is that possible? as disabled it won't let me add to database

here the link: http://jsfiddle.net/vpfk6dce/

2
  • Inserting to databse using AJAX? PHP? Commented Aug 20, 2019 at 2:06
  • using php code to insert to db Commented Aug 20, 2019 at 2:06

1 Answer 1

3

You can add a hidden input type then just add the date value to it. Then add it to database using $_POST['hiddendate'].

$(function() {
    $(".firstcal").datepicker({
        dateFormat: "dd/mm/yy",
        onSelect: function(dateText, instance) {
            date = $.datepicker.parseDate(instance.settings.dateFormat, dateText, instance.settings);
            date.setMonth(date.getMonth() + 6);
            $(".secondcal").datepicker("setDate", date);
            $(".hiddendate").datepicker("setDate", date); //added
        }
    });
    $(".secondcal").datepicker({
        dateFormat: "dd/mm/yy"
    }).attr("disabled", 'disabled');
    
    //added
    $(".hiddendate").datepicker({
        dateFormat: "dd/mm/yy"
    });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.14/themes/smoothness/jquery-ui.css" rel="stylesheet"/>

First Date:<input type="text" class="firstcal">
Last Date:<input type="text" class="secondcal">
<input type="hidden" name="hiddendate" class="hiddendate">

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.