Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

limit a second date with jquery datepicker

Posted on 2014-09-16
3
Medium Priority
?
535 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 2000 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

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

Question has a verified solution.

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

Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…
Suggested Courses

688 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