Skip to content

Instantly share code, notes, and snippets.

@hlee
Created June 25, 2013 15:58
Show Gist options
  • Save hlee/5859665 to your computer and use it in GitHub Desktop.
Save hlee/5859665 to your computer and use it in GitHub Desktop.
<select id="CategoryList" onchange="CategoryList_OnChange()">
<option value="" selected="selected"></option>
<option value="1" selected="selected">Food</option>
<option value="2" selected="selected">Toys</option>
<option value="3" selected="selected">Books</option>
</select>
<select id="ProductList"></select>
<script src="../../Scripts/jquery-1.3.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
function CategoryList_OnChange() {
var selected = $('#CategoryList').val();
if (selected != null && selected != '') {
$.getJSON('SelectList/ProductList/' + selected, function(selectList) {
$('#ProductList option').remove();
$.each(selectList, function(index, value) {
$('#ProductList').append("<option value='" + value.Value + "'>" + value.Text + "</option>");
});
});
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment