-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathdemo.html
81 lines (71 loc) · 1.85 KB
/
demo.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
<html>
<head>
<title>Zip Code Lookup Demo</title>
<style>
form label, form input {
display: block;
}
</style>
</head>
<body>
<form id="theform">
<label for="zip">
Zip:
<input type="text" id="zip" />
</label>
<label for="city">
City:
<input type="text" id="city" />
</label>
<label for="state">
State:
<input type="text" id="state" />
</label>
<label for="state-short">
State Short:
<input type="text" id="state-short" />
</label>
<label for="country">
Country:
<input type="text" id="country" />
</label>
<input type="submit" />
</form>
<script type="text/javascript" src="https://code.jquery.com/jquery-1.11.2.min.js"></script>
<script type="text/javascript" src="jquery.ziptastic.js"></script>
<script type="text/javascript">
(function($) {
$(function() {
var duration = 500;
var elements = {
country: $('#country'),
state: $('#state'),
state_short: $('#state-short'),
city: $('#city'),
zip: $('#zip')
}
// Initially hide the city/state/zip
elements.country.parent().hide();
elements.state.parent().hide();
elements.state_short.parent().hide();
elements.city.parent().hide();
// Initialize the ziptastic and bind to the change of zip code
var options = {
"key": "your-api-key-here",
"country": "US"
}
elements.zip.ziptastic(options)
.on('zipChange', function(evt, country, state, state_short, city, zip) {
// Country
elements.country.val(country).parent().show(duration);
// State
elements.state_short.val(state_short).parent().show(duration);
elements.state.val(state).parent().show(duration);
// City
elements.city.val(city).parent().show(duration);
});
});
}(jQuery));
</script>
</body>
</html>