Solved

jquery date picker

Posted on 2014-09-24
7
273 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

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.

Question has a verified solution.

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

There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
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…

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