Solved

limit a second date with jquery datepicker

Posted on 2014-09-16
3
490 Views
Last Modified: 2014-09-16
I am using jquery datepicker for a "from" and "to" date.
I am trying to limit the "to" date to 7 business days (9 actual days) after the from date.
User should be able to pick any date after 2days in the future and then the "to" date would be any date from that date up to 9 days out.

I tried this and it works as long as the from date is the first available date, but fails after that.
  $(function() {
    $( "#from" ).datepicker({
      defaultDate: "+2d",
      minDate: "+2d",
      changeMonth: true,
      beforeShowDay: $.datepicker.noWeekends,
      onClose: function( selectedDate ) {
        $( "#to" ).datepicker( "option", "minDate", selectedDate );
      }
    });
   
    $( "#to" ).datepicker({
          defaultDate: "+2d",
      maxDate: "1w +4d",
      changeMonth: true,
      beforeShowDay: $.datepicker.noWeekends,
      onClose: function( selectedDate ) {
        $( "#from" ).datepicker( "option", "maxDate", selectedDate );
      }
    });
  });

I don't know how to get the "from" date and add "1w +4d" to it.

Thanks for any help
james
0
Comment
Question by:cubbyboy57
  • 2
3 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 40327074
Test page : http://jsfiddle.net/ycsak53c/1/

 $(function() {
    $( "#from" ).datepicker({
      defaultDate: "+2d",
      changeMonth: true,
      beforeShowDay: $.datepicker.noWeekends,
      onClose: function( selectedDate ) {
        $( "#to" ).datepicker( "option", "minDate", selectedDate );
        var maxDate = new Date(new Date(selectedDate).getTime() + (4 * 7 + 2) * 24 * 3600 * 1000);
        $( "#to" ).datepicker( "option", "maxDate", maxDate );
      }
    });
    
    $( "#to" ).datepicker({ 
          defaultDate: "+2d",
      changeMonth: true,
      beforeShowDay: $.datepicker.noWeekends,
      onClose: function( selectedDate ) {
        $( "#from" ).datepicker( "option", "maxDate", selectedDate );
      }
    });
  });

Open in new window

0
 

Author Comment

by:cubbyboy57
ID: 40327161
This works!  you have 30 days ahead, but I figured it out.

Thanks for the quick reply!
0
 
LVL 82

Expert Comment

by:leakim971
ID: 40327173
(4 * 7 + 2) -> (1 * 7 + 4)

my bad...
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now