• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1142
  • Last Modified:

jQuery date picker default year selector when blank

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
Matthew_Way
Asked:
Matthew_Way
  • 3
  • 2
1 Solution
 
marceloOrigoniCommented:
did you try this?



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

 Marcelo
0
 
Matthew_WayAuthor Commented:
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
 
ventaurCommented:
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
Matthew_WayAuthor Commented:
@ventaur
Great thanks so much, amazing just how many options are available under jQuery.
0
 
ventaurCommented:
I think, perhaps, the author chose the wrong comment as the accepted solution.
0
 
ventaurCommented:
You're welcome! Yes, there are a ton of options with jQuery. Too many to know them all.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now