Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Aug 2011
    Posts
    134
    Thanks
    20
    Thanked 0 Times in 0 Posts

    jquery datepicker with maxDate

    Code:
    <script type="text/javascript">
    $(function(){
       $("#testdate").datepicker({ dateFormat: 'm/d/yy', minDate: 0,maxDate:minDate + 14});
    });
    </script>
    
    <script type="text/javascript"> 
    $(function() { 
       $('#date').datepicker({ 
           dateFormat: 'm/d/yy', minDate: new Date(<?php echo $this->y;?>, <?php echo (($this->m) - 1);?>, <?php echo ($this->d);?>), 
           beforeShowDay: $.datepicker.noWeekends 
       }); 
    }); 
    </script>
    I have a couple of datepickers that work fine. But in both cases above, I want to limit the selection of date to just two weeks from the startdate.

    .i.e if the start date in the above datepicker starts from 08/12/2012, the datepicker should allow me to only select dates upto two weeks from that date.

    I tried maxDate:minDate + 14 which didnt work.

  • #2
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts
    give this a try

    Quote Originally Posted by coding_begins View Post
    Code:
    <script type="text/javascript">
    $(function(){
    var MyMinDate = $("#testdate" ).datepicker( "option", "minDate" );
       $("#testdate").datepicker({ dateFormat: 'm/d/yy', minDate: 0,maxDate:MyMinDate + 14});
    });
    </script>
    
    <script type="text/javascript"> 
    $(function() { 
       $('#date').datepicker({ 
           dateFormat: 'm/d/yy', minDate: new Date(<?php echo $this->y;?>, <?php echo (($this->m) - 1);?>, <?php echo ($this->d);?>), 
           beforeShowDay: $.datepicker.noWeekends 
       }); 
    }); 
    </script>
    I have a couple of datepickers that work fine. But in both cases above, I want to limit the selection of date to just two weeks from the startdate.

    .i.e if the start date in the above datepicker starts from 08/12/2012, the datepicker should allow me to only select dates upto two weeks from that date.

    I tried maxDate:minDate + 14 which didnt work.

  • Users who have thanked DanInMa for this post:

    coding_begins (03-07-2012)

  • #3
    Regular Coder
    Join Date
    Aug 2011
    Posts
    134
    Thanks
    20
    Thanked 0 Times in 0 Posts
    thanks it works for the first one..it doesn't work for this one though..
    Code:
    <script type="text/javascript">
    $(function() {
    	var MyMinDate = $("#date" ).datepicker( "option", "minDate" );
       $('#date').datepicker({
    	   dateFormat: 'm/d/yy', minDate: new Date(<?php echo $this->y;?>, <?php echo (($this->m) - 1);?>, <?php echo ($this->d);?>),
    	   maxDate:MyMinDate + 14 ),
           beforeShowDay: $.datepicker.noWeekends
       });
    });
    </script>
    Last edited by coding_begins; 03-07-2012 at 03:59 AM.

  • #4
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts
    Quote Originally Posted by coding_begins View Post
    thanks it works for the first one..it doesn't work for this one though..
    Code:
    <script type="text/javascript">
    $(function() {
    	var MyMinDate = $("#date" ).datepicker( "option", "minDate" );
       $('#date').datepicker({
    	   dateFormat: 'm/d/yy', minDate: new Date(<?php echo $this->y;?>, <?php echo (($this->m) - 1);?>, <?php echo ($this->d);?>),
    	   maxDate:MyMinDate + 14 ),
           beforeShowDay: $.datepicker.noWeekends
       });
    });
    </script>
    well thats essentially the same. if its on the same page perhaps usea different variable name?
    Last edited by DanInMa; 03-07-2012 at 04:32 AM.

  • #5
    Regular Coder
    Join Date
    Aug 2011
    Posts
    134
    Thanks
    20
    Thanked 0 Times in 0 Posts
    well it's on a different page and i tried the above..but it doesn't show me the datepicker..

  • #6
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts
    troubleshoot. try jsut a basic datepicker w/o the php date , make sure #date exists of course


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •