-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdate.js
More file actions
69 lines (60 loc) · 1.64 KB
/
date.js
File metadata and controls
69 lines (60 loc) · 1.64 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
window.onload = dateJS;
function dateJS() {
var elDate = document.getElementById('date'),
elOptions = document.getElementById('options'),
dateFormats = ["MDY", "DMY", "YMD"],
today = new Date();
CreateOptions();
DisplayDate();
function DisplayDate(format) {
var formattedDate = '';
switch (format) {
case "MDY":
formattedDate += (today.getMonth() + 1) + "/"
+ today.getDate() + "/"
+ today.getFullYear();
break;
case "DMY":
formattedDate += today.getDate() + "/"
+ (today.getMonth() + 1) + "/"
+ today.getFullYear();
break;
case "YMD":
formattedDate += today.getFullYear() + "/"
+ (today.getMonth() + 1) + "/"
+ today.getDate();
break;
default:
formattedDate += (today.getMonth() + 1) + "/"
+ today.getDate() + "/"
+ today.getFullYear();
break;
};
elDate.innerHTML = formattedDate;
}
function CreateOptions() {
if (elOptions) {
//Create a radio button for each date format option in array
for (var i = 0; i < dateFormats.length; i++) {
var elDateFormat = document.createElement('input');
var value = dateFormats[i];
elDateFormat.name = 'dateFormats';
elDateFormat.value = value;
elDateFormat.type = 'radio';
elDateFormat.onclick = function() {
DisplayDate(this.value);
};
var label = document.createElement('label');
label.appendChild(elDateFormat);
label.appendChild(document.createTextNode(dateFormats[i]));
var div = document.createElement('div');
div.setAttribute('class', 'radio-inline');
div.appendChild(label);
elOptions.appendChild(div);
};
}
else {
DisplayDate('MDY');
};
}
}