Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Justin Esders
9,154 PointsChaining Select Lists
Hi all I am recently new to javascript, ajax, and jquery.
I was wondering if anyone knows how to or has a good source on how to add items to a 2nd select list after an item in the first select list is selected.
I want to fill the 2nd select list from a json file i have but cant figure out how.
I can not use php.
$(document).ready(function () {
var $select = $("#genreSelectList");
$select.click(function() {
/* start Ajax call */
$.getJSON("data/songs.json", function (data) {
$select.html("");
$.each(data.rock, function (key, val) {
$select.append('<option id = "multiple" + val.artist + "'>' + val.title + '</option>');
});
}
this is the code i have just didnt know if it was correct because it doesnt run when using xampp
I cant use plugins or php.
Can someone help?
3 Answers
James Barnett
39,199 Points-
James Barnett
39,199 PointsTry out this code:
I fixed some unclosed functions.
$(document).ready(function () {
var $select = $("#genreSelectList");
$select.click(function() {
/* start Ajax call */
$.getJSON("data/songs.json", function (data) {
$select.html("");
$.each(data.rock, function (key, val) {
$select.append( '<option id = "multiple" + val.artist + >' + val.title + '</option>');
})
});
});
});
Justin Esders
9,154 PointsStill does not work for some reason. I basically need to populate the songs into the multiselect list when the user clicks on the drop down and picks the genre of song. Is there a way to attach things so i can get help figuring this out?