Solved

jquery date picker

Posted on 2014-09-24
7
277 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
The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

 
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

Turn Insights Into Action

You’ve already invested in ITSM tools, chat applications, automation utilities, and more. Fortify these solutions with intelligent communications so you can drive business processes forward.

With xMatters, you'll never miss a beat.

Question has a verified solution.

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

OverviewThis article demonstrates a simple search form using AJAX. The purpose of the article is to demonstrate how to use the same code to render a page and javascript (JQuery) and AJAX to make subsequent calls to refine the results. The princip…
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…

696 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