Back
Syntax
Study
Editor
Mode:
HTML
CSS
JavaScript
PHP
Reset
Run »
HTML / CSS / JS
$("#country").on("change", function() { const countryId = $(this).val(); $("#state").html(`<option>Loading...</option>`); $.getJSON("/api/states?country=" + countryId, function(states) { const options = states.map(s => `<option value="${s.id}">${s.name}</option>` ).join(""); $("#state").html(`<option value="">Select state...</option>` + options); }); });
Result
Open