Solved

jQuery date picker default year selector when blank

Posted on 2010-11-26
6
1,107 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to check or uncheck a checkbox using the id of the checkbox 2 23
Compute age Html 2 27
Session on Html 8 42
allow link tag to be submit like form 15 28
What is a Lightbox? A Lightbox is the effect you see when you click, for example, an image and the screen fades out and up pops the same image but in its full size dimensions. There are lots of Lightbox effects for jQuery. Problem is they are a…
Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
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)
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…

730 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