简体   繁体   中英

Add days to html form date picker

So what am i doing wrong here? I have a form with 2 date html datepickers, 1 is for when they arrive where the date is min today, the other one im trying to do so they can only book min of 1 week.

If you guys have any idea how to do it easier please tell me that would help me a lot!

<script src="jquery.js"></script>
<!-- <script src="booking.js"></script> -->

<script type="text/javascript">
        var today = new Date().toISOString().split('T')[0];
document.getElementsByName("a_Date")[0].setAttribute('min', today);

    var vDate = (today).getDate(today);
    console.log(vDate);
    console.log(today);


        document.getElementsByName("v_Date")[0].setAttribute('min', vDate); 
</script>

Well, if I clearly understood what you want to achieve here, you must to restrict an amount of days between two dates. In this case, 1 week. There are some requirements beside this, for example, you want to initiate the first datepicker element from today as the minimum date.

I made this example to you, then you can just fit to your elements.

 <html lang="en"> <head> <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css"> <script src="//code.jquery.com/jquery-1.10.2.js"></script> <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script> <script> $(function() { $( "#from" ).datepicker({ minDate: 0, onClose: function( selectedDate ) { var newDate = new Date(selectedDate); newDate.setDate(newDate.getDate() + 7) $( "#to" ).datepicker( "option", "minDate", newDate); } }); $( "#to" ).datepicker(); }); </script> </head> <body> <label for="from">From</label> <input type="text" id="from" name="from"> <label for="to">to</label> <input type="text" id="to" name="to"> </body> </html> 

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