Last active
August 29, 2015 14:06
-
-
Save dacur/c425d87c414365bcf187 to your computer and use it in GitHub Desktop.
User inputs DOB with dropdowns for month and date, with a text box for year. Since month is 'January, February, etc.' and we need its numerical value, we included a switch statement to convert it to a number. We then add those together into 'birthday', pass that value to CurrentAge(), which returns the user's age as YEAR-MO-DY.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $('#birthdayBtn').on('click', function(){ | |
| var month = $('#birth_month').val(); | |
| switch (month){ | |
| case 'January': | |
| month = 1; | |
| break; | |
| case 'February': | |
| month = 2; | |
| break; | |
| case 'March': | |
| month = 3; | |
| break; | |
| case 'April': | |
| month = 4; | |
| break; | |
| case 'May': | |
| month = 5; | |
| break; | |
| case 'June': | |
| month = 6; | |
| break; | |
| case 'July': | |
| month = 7; | |
| break; | |
| case 'August': | |
| month = 8; | |
| break; | |
| case 'September': | |
| month = 9; | |
| break; | |
| case 'October': | |
| month = 10; | |
| break; | |
| case 'November': | |
| month = 11; | |
| break; | |
| case 'December': | |
| month = 12; | |
| break; | |
| } | |
| var day = $('#birth_day').val(); | |
| var year = $('#birth_year').val(); | |
| var birthday = (year + "-" + month + "-" + day); | |
| var current_age = CurrentAge(birthday); | |
| alert(_age); | |
| }); | |
| } | |
| }; | |
| function CurrentAge(birthday){ | |
| var dob = new Date(birthday); | |
| var today = new Date(); | |
| _age = Math.floor((today-dob) / (365.25 * 24 * 60 * 60 * 1000)); | |
| return _age; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #pageBirthday.page | |
| .content | |
| br | |
| h4.centeredText What is your date of birth? | |
| br | |
| h4 Month | |
| select.form-control#birth_month | |
| option Please choose a month... | |
| option January | |
| option February | |
| option March | |
| option April | |
| option May | |
| option June | |
| option July | |
| option August | |
| option September | |
| option October | |
| option November | |
| option December | |
| h4 Day | |
| select.form-control#birth_day | |
| option Please choose a date... | |
| option 1 | |
| option 2 | |
| option 3 | |
| option 4 | |
| option 5 | |
| option 6 | |
| option 7 | |
| option 8 | |
| option 9 | |
| option 10 | |
| option 11 | |
| option 12 | |
| option 13 | |
| option 14 | |
| option 15 | |
| option 16 | |
| option 17 | |
| option 18 | |
| option 19 | |
| option 20 | |
| option 21 | |
| option 22 | |
| option 23 | |
| option 24 | |
| option 25 | |
| option 26 | |
| option 27 | |
| option 28 | |
| option 29 | |
| option 30 | |
| option 31 | |
| h4 Year | |
| input(type='text', id='birth_year', class='form-control', placeholder='Year') | |
| button.btn.btn-default.form-control.button.trackit#birthdayBtn(type='button') Submit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment