Solved

jQuery date picker default year selector when blank

Posted on 2010-11-26
6
1,098 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
Comment Utility
did you try this?



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

 Marcelo
0
 

Author Comment

by:Matthew_Way
Comment Utility
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
Comment Utility
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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

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

Expert Comment

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

Expert Comment

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

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Adding Extra Information box 4 23
Hovering effect 9 28
Bootstap Icons 3 18
Return data with AJAX, JQUERY and PHP 13 26
Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now