?
Solved

jQuery date picker default year selector when blank

Posted on 2010-11-26
6
Medium Priority
?
1,130 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 2000 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 

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

Industry Leaders: 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

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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.
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…
Suggested Courses

765 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