Solved

jQuery date picker default year selector when blank

Posted on 2010-11-26
6
1,102 Views
Last Modified: 2012-05-10
Hi,

We are using jquery.ui.datepicker to enter birth dates.
The average age of the birth dates in our database is 25 years old.

We bind the date picker like this;
$('#birthDate').datepicker({ yearRange: '1910:2005' }).change(calcAge);
Which is working well.

What we want is when the datepicker is clicked on and the current birth date is blank that the year selector defaults to 1985.
So the user dosn't have to scroll all the way from 1910
0
Comment
Question by:Matthew_Way
  • 3
  • 2
6 Comments
 
LVL 2

Expert Comment

by:marceloOrigoni
ID: 34217591
did you try this?



$('#birthDate').datepicker({ yearRange: '1910:2005' }).change(calcAge);
$('#birthDate').datepicker("setDate", '01/01/1985');

 Marcelo
0
 

Author Comment

by:Matthew_Way
ID: 34224293
That didn't seem to work.

Also I don't want to set the value in the field but just change the default list position in the year drop down.

0
 
LVL 6

Accepted Solution

by:
ventaur earned 500 total points
ID: 34233787
Try this:

$('#birthDate').datepicker({ defaultDate: '-25y' });

Open in new window


It should default the date picker to the current date minus your average age (25 years). It keeps things relative too so you don't have to remember to update it when your date range changes later.
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

Author Comment

by:Matthew_Way
ID: 34246850
@ventaur
Great thanks so much, amazing just how many options are available under jQuery.
0
 
LVL 6

Expert Comment

by:ventaur
ID: 34248440
I think, perhaps, the author chose the wrong comment as the accepted solution.
0
 
LVL 6

Expert Comment

by:ventaur
ID: 34248445
You're welcome! Yes, there are a ton of options with jQuery. Too many to know them all.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
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…

770 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