Last active
August 29, 2015 14:24
-
-
Save sergiors/72c734eb821f0e5eeebe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// see before https://github.com/sergiors/vanilla | |
(function() { | |
'use strict'; | |
var state = document.getElementById('address_state'); | |
state.on('change', function() { | |
var city = document.getElementById('address_city'); | |
city.setAttribute('disabled', true); | |
if (!state.value) { | |
return; | |
} | |
$.getJSON('http://example.com/cities', { | |
state: state.value | |
}, function(data) { | |
var select = document.createElement('select'); | |
select.setAttributes(city.getAttributes()); | |
for (var key in data) { | |
var option = document.createElement('option'); | |
option.value = data[key].id; | |
option.text = data[key].name; | |
select.options.add(option); | |
} | |
select.removeAttribute('disabled'); | |
city.outerHTML = select.outerHTML; | |
}); | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment