-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.html.bak
41 lines (36 loc) · 995 Bytes
/
index.html.bak
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
---
layout: default
---
<script>
const citiesByName = {
{% for city in site.cities %}
"{{city.title}}": "{{city.slug}}",
{% endfor %}
};
function handleCitySelect(event) {
event.preventDefault();
const form = event.target;
const slug = citiesByName[form.city.value];
if (!slug) {
const error = document.getElementById('error');
error.innerHTML = "Please select a valid city name.";
} else {
window.location = window.location + slug;
}
}
</script>
<form onsubmit="handleCitySelect(event)">
<p>
<label>
City name:
<input name="city" list="cities" placeholder="City, State" />
</label>
</p>
<p id="error"></p>
<button type="submit">Find alternatives to the police</button>
</form>
<datalist id="cities">
{% for city in site.cities %}
<option value="{{ city.title }}">
{% endfor %}
</datalist>