Solved

jquery date picker

Posted on 2014-09-24
7
276 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
[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
  • 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

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…
This article discusses how to create an extensible mechanism for linked drop downs.
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…

737 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