I have this code that pre-fills my website with user's city & state based off of a zip-code that is entered into my contact form.
It works perfect in Google Chrome, and Firefox, but it is not working in IE.
Does anyone know why, and if so, can you fix the code for me?
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
<!--Realtime City/State Update From Zip Code Post-in-->
<script>
$(document).ready(function () {
var zip = $("#zip").val();
$.getJSON('http://zip.elevenbasetwo.com/v2/US/' + zip, function (json) {
$('#city').val(json.city);
});
$.getJSON('http://zip.elevenbasetwo.com?zip=' + zip, function (json) {
$('#state').val(json.state);
});
});
</script>
<!--On Edit/Keyup City/State Update-->
<script>
$(document).on("keyup", "#zip", function () {
var zip = this.value;
$.getJSON('http://zip.elevenbasetwo.com/v2/US/' + zip, function (json) {
$('#city').val(json.city);
});
$.getJSON('http://zip.elevenbasetwo.com?zip=' + zip, function (json) {
$('#state').val(json.state);
});
});
</script>
Edit
What I mean by not working
is that on Google Chrome and Firefox my City & State fields in my contact form will automatically be pre-filled based on the zip-code that is entered.
However in IE (version 9 for me), the City & State fields are not pre-populating like they should.