JSFiddle - React, Tailwind, and code Playground
by pradeep
HTML
<p>Zip Code: <input type="text" id="zip" /></p>
<p>City: <input type="text" id="city" /></p>
<p>State: <input type="text" id="state" /></p>
JavaScript
$(document).ready(function() {
$("#zip").keyup(function() {
var el = $(this);
$("#city").val(null);
$("#state").val(null);
if (el.val().length === 5) {
$.ajax({
url: "http://zip.elevenbasetwo.com",
cache: false,
dataType: "json",
type: "GET",
data: "zip=" + el.val(),
success: function(result, success) {
$("#city").val(result.city);
$("#state").val(result.state);
}
});
}
});
});