Solved

jquery date picker

Posted on 2014-09-24
7
269 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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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)

707 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

17 Experts available now in Live!

Get 1:1 Help Now