?
Solved

minDate maxDate issue with jquery ui datepicker

Posted on 2009-12-19
4
Medium Priority
?
1,745 Views
Last Modified: 2013-11-13
Hi,

I have a "startDate" field and an "endDate" field.  I need to know the following:

1. The code that sets the maxDate parameter for the "startDate" field based upon the "endDate" selection.

2.  The code that sets the minDate parameter for the "endDate" field based upon the "startDate" selection.

I need this code to work with the jquery-ui-1.7.2.custom.min.js file that you would download from the jquery ui site so that I can use the theme I rolled.

The code below is what I have so far that works.  If you could just tell me what I need to add to this, you would be awesome.  Thanks for the help.
<script type="text/javascript">
        $(function() {
                $('#startDate').datepicker({
                        minDate: 0,             
                        dateFormat: 'yy-mm-dd',
                        numberOfMonths: 3,
                        showButtonPanel: false  
                });
                $('#endDate').datepicker({
                        dateFormat: 'yy-mm-dd',
                        numberOfMonths: 3,
                        showButtonPanel: false  
                });
        });
</script>

Open in new window

0
Comment
Question by:joshuajohnhutchison
  • 2
  • 2
4 Comments
 
LVL 10

Accepted Solution

by:
Terry_focus earned 2000 total points
ID: 26095709
Hi,

I think this is what you need
$(function() {
    $('#startDate').datepicker({
            minDate: 0,             
            dateFormat: 'yy-mm-dd',
            numberOfMonths: 3,
            showButtonPanel: false  
    }).change(function(){
		//Break open your dates to create a date object
		var datePart = this.value.split("-");
		var d = new Date();
		d.setYear(datePart[0]);
		d.setMonth(parseInt(datePart[1],10)-1);//JavaScript is month -1
		d.setDate(datePart[2]);
		//Use getter an setters to adjust end date picker
		$('#endDate').datepicker('option', 'minDate',d);
	});
    $('#endDate').datepicker({
            dateFormat: 'yy-mm-dd',
            numberOfMonths: 3,
            showButtonPanel: false
    }).change(function(){
		var datePart = this.value.split("-");
		var d = new Date();
		d.setYear(datePart[0]);
		d.setMonth(parseInt(datePart[1],10)-1);
		d.setDate(datePart[2]);
		//Use getter an setters to adjust end date picker
		$('#startDate').datepicker('option', 'maxDate',d);
	});
});

Open in new window

0
 
LVL 1

Author Comment

by:joshuajohnhutchison
ID: 26097215
Dude, your a genius and my hero.  Well done :)
0
 
LVL 1

Author Closing Comment

by:joshuajohnhutchison
ID: 31668132
Excellent fix her! Nowhere on the internet can you find this solution except here! Trust me... I scoured it.
0
 
LVL 10

Expert Comment

by:Terry_focus
ID: 26097323
No probs, thanks for the points
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

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

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.
Article by: evilrix
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
The viewer will learn how to dynamically set the form action using jQuery.
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)
Suggested Courses

621 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