Solved

jquery date picker

Posted on 2014-09-24
7
271 Views
Last Modified: 2014-09-25
I have the date picker that will select a date of birth. When selection is made I need disable some of the options on the dropdown. To be more specific, When I am selecting the DOB I am calculating the age of the person, Now if the DOB is 15 years    and 9  month I need to disable some of the drop down options.

function calcage() {
				var vdob = new Date(document.getElementById("dateofbirth").value);
				
				var vcurrentTime = new Date();
				var vyear = vcurrentTime.getFullYear();
				var vyear1 = vdob.getFullYear();
				var vage = vyear-vyear1
				var vcurrage = vcurrentTime.getTime() - vdob.getTime();
				vcurrage = Math.floor(vcurrage / (1000 * 60 * 60 * 24 * 365.25));
				document.getElementById("age").value=vcurrage+' years';
	}

Open in new window

0
Comment
Question by:erikTsomik
  • 4
  • 3
7 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 40342197
           document.getElementById("age").value=vcurrage+' years'; // your current line 10
           if(vcurrage<15) {
               $("#dropdown1").hide();
               $("#dropdown2").hide();
           }
           else if(vcurrage>=15 && vcurrage<30) {
               $("#dropdown1").show();
               $("#dropdown2").hide();
           }
           else {
               $("#dropdown1").show();
               $("#dropdown2").show();
           }
}

Open in new window

0
 
LVL 19

Author Comment

by:erikTsomik
ID: 40342216
well What I need is to make sure that if the user 15 years and 9 month old (this condition is critical).
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 40342438
function calcage() {
     var vdob = new Date(document.getElementById("dateofbirth").value);
     var today = new Date();
     var year = today.getFullYear() - vdob.getFullYear();
     var month = today.getMonth() - vdob.getMonth();
     var notYet = month<0;
     year = notYet?(year-1):year;
     month = notYet?(12-month):month;
     if(year<15||(year==15&&month<=9)) { // if less than 15 years and 9 month old
               // hide dropdown
               $("#dropdown1").hide();
               $("#dropdown2").hide();
           }     
}

Open in new window

0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 19

Author Comment

by:erikTsomik
ID: 40342609
I tried but the formula does not. FOr example the persons birthday is on 3/24/1999 so today he is exactly 15 years 9 month old, if I shift the date to 3/25/1998 then it is still shows me 15 years and 6 month event though his 15 years and 9 month will be tomorrow
0
 
LVL 82

Expert Comment

by:leakim971
ID: 40342655
3/24/1999 => 15y6m not 9m
0
 
LVL 19

Author Comment

by:erikTsomik
ID: 40342682
I am just testing a different case scenario if the rule is 15 years and 6 month
0
 
LVL 82

Expert Comment

by:leakim971
ID: 40342688
so what ? the function give you year and mont, you do what you want with on line 9

if(year<15||(year==15&&month<=6)) { // if less than 15 years and 6 month old
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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 …
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 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)

867 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

21 Experts available now in Live!

Get 1:1 Help Now