简体   繁体   中英

Show date 3 days later than Date Picker date in text field

I am using this date picker code.

var d = new Date();
$(function () {
    $("#datepicker").datepicker({
        minDate: d,
        dateFormat: 'mm-dd-yy'
    });
});

What I need is if I select a date then I a date 3 days later comes into the next text field. For example. I select a date 02-12-2016 and in the next text field the date is 02-15-2016

Answer to your question is below :

Just Replace the 3 with the no. of days u want to add


<!DOCTYPE html>
<html>
<head>
    <title></title>
    <script type="text/javascript">

    $(document).ready(function () {
        $('#inp_date').datepicker();
    });

    function getdate() {

        var tt = document.getElementById('inp_date').value;

        var date = new Date(tt);
        var newdate = new Date(date);

        newdate.setDate(newdate.getDate() + 3);

        var dd = newdate.getDate();
        var mm = newdate.getMonth() + 1;
        var y = newdate.getFullYear();

        var someFormattedDate = mm + '/' + dd + '/' + y;
        document.getElementById('output_Date').value = someFormattedDate;
    }
</script>
</head>
<body>
<input id="inp_date" type="text" /><br>
    <input type="button" onclick="getdate()" value="Fill Follow Date" /><hr>

    <input id="output_Date" type="text" />
</body>
</html>

use this code to add 3 days to the current date

$date = date('Y-m-d', strtotime('+3 days'));

then echo $date as value in your text field..

note: this is done in php.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM