-
Notifications
You must be signed in to change notification settings - Fork 41
/
index.html
124 lines (117 loc) · 3.47 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Pure JS datalist polyfill</title>
<link rel="stylesheet" href="style.css"/>
<style>
body {
font: 14px/1.4 Georgia, Serif;
}
code {
margin: 1em;
display: block;
}
</style>
</head>
<body>
<div class="main">
<p>
Sample code for <a href="https://github.com/fyrd/purejs-datalist-polyfill">pure JS polyfill</a>. Selecting a value will trigger a 'change' event and alert the value.
</p>
<p>
To work in IE8 & 9, you must start and end the datalist options with the following tags (view source for example)
<code>
<!--[if lte IE 9]><select data-datalist="<b>YOUR-LIST-ID</b>"><![endif]-->
</code>
<code>
<!--[if lte IE 9]></select><![endif]-->
</code>
</p>
<p>
<label>Select a state:</label>
<input type="text" list="states">
</p>
<datalist id="states">
<!--[if lte IE 9]><select data-datalist="states"><![endif]-->
<option value="Alabama">
<option value="Alaska">
<option value="Arizona">
<option value="Arkansas">
<option value="California">
<option value="Colorado">
<option value="Connecticut">
<option value="Delaware">
<option value="Florida">
<option value="Georgia">
<option value="Hawaii">
<option value="Idaho">
<option value="Illinois">
<option value="Indiana">
<option value="Iowa">
<option value="Kansas">
<option value="Kentucky">
<option value="Louisiana">
<option value="Maine">
<option value="Maryland">
<option value="Massachusetts">
<option value="Michigan">
<option value="Minnesota">
<option value="Mississippi">
<option value="Missouri">
<option value="Montana">
<option value="Nebraska">
<option value="Nevada">
<option value="New Hampshire">
<option value="New Jersey">
<option value="New Mexico">
<option value="New York">
<option value="North Carolina">
<option value="North Dakota">
<option value="Ohio">
<option value="Oklahoma">
<option value="Oregon">
<option value="Pennsylvania">
<option value="Rhode Island">
<option value="South Carolina">
<option value="South Dakota">
<option value="Tennessee">
<option value="Texas">
<option value="Utah">
<option value="Vermont">
<option value="Virginia">
<option value="Washington">
<option value="West Virginia">
<option value="Wisconsin">
<option value="Wyoming">
<!--[if lte IE 9]></select><![endif]-->
</datalist>
<p>
<label>Select placeholder text:</label>
<input type="text" list="samples">
</p>
<datalist id="samples">
<!--[if lte IE 9]><select data-datalist="samples"><![endif]-->
<option value="foo">
<option value="bar">
<option value="baz">
<option value="lorem ipsum">
<option value="example.com">
<!--[if lte IE 9]></select><![endif]-->
</datalist>
</div>
<script>
(function() {
var inputs = document.getElementsByTagName('input');
for( var i = 0; i < inputs.length; i++ ) {
var input = inputs[i];
input.onchange = function(evt) {
var elem = evt ? evt.target : window.event.srcElement;
alert('new value: ' + elem.value);
};
}
}());
</script>
<script src="datalist.polyfill.min.js"></script>
</body>
</html>