Solved

limit a second date with jquery datepicker

Posted on 2014-09-16
3
507 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:James Stone
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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:James Stone
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Github api to fetch the number of collaborators in a git repo 1 33
Compute age Html 2 27
How do i use the await event in php echo 5 19
Diff of the day 2 10
How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
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…

730 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