-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
59 lines (57 loc) · 1.51 KB
/
index.html
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
<!doctype html>
<html lang="en-US">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Date in Spanish</title>
<style>
body {
text-align: center;
}
label {
font-weight: bold;
}
output {
display: block;
}
</style>
</head>
<body>
<main>
<h1>Date in Spanish</h1>
<form>
<p>
<label for="input">Date:</label>
<br />
<input type="date" id="input" name="input" />
</p>
<p>
<label for="output">Spanish:</label>
<output for="input" id="output" name="output" aria-live="polite"><time lang="es-MX"></time><noscript>Please enable JavaScript</noscript></output>
</p>
</form>
</main>
<script>
const form = document.forms[0]
const input = form.elements.input
const output = form.elements.output
const time = output.getElementsByTagName('time')[0]
const format = (new Intl.DateTimeFormat('es-MX', { timeZone: 'UTC', dateStyle: 'long' })).format
form.addEventListener('submit', (e) => {
e.preventDefault()
if (input.valueAsDate) {
time.dateTime = input.value
time.textContent = format(input.valueAsDate)
output.style.display = null
} else {
output.style.display = 'none'
time.textContent = ''
time.dateTime = ''
}
})
input.addEventListener('change', (e) => { e.currentTarget.form.requestSubmit() })
input.addEventListener('input', (e) => { e.currentTarget.form.requestSubmit() })
form.requestSubmit()
</script>
</body>
</html>