-
Notifications
You must be signed in to change notification settings - Fork 0
/
donate.js
34 lines (28 loc) · 1.02 KB
/
donate.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// form display script
var personalForm = document.querySelector('#personal-info'),
medicalForm = document.querySelector('#medical-info'),
medicalBlock = document.querySelector('.medical-info');
personalForm.addEventListener('submit', (e) => {
e.preventDefault();
medicalBlock.style.display = "block";
})
// Date Validator
var dob = document.querySelector('#dob');
dob.addEventListener('change', checkAge);
function checkAge(e) {
console.log(dob.value);
var date = dob.value.split('-'),
year = date[0],
month = date[1],
day = date[2],
today = new Date();
var age = today.getFullYear() - year;
var m = today.getMonth() - month;
if (m < 0 || (m === 0 && today.getDate() < Date(dob.value))) {
age--;
}
if (age < 18) {
alert('You are not eligible to donate blood');
dob.value = '';
}
}