Monday 26 August 2013

Populating two related select boxes from an xml file

Populating two related select boxes from an xml file

I have an xml file which for every car make displays all the models and
for every model displays all the versions.
Using jquery, I want to populate two select boxes with this file, the
first box displays the makes the second displays for the selected make,
all the models and the versions. the xml file looks like this:
<carmake>
<makename></makename>
<model>
<modelname>name1</modelname>
<version>something...</version>
<version>anotherthg...</version>
</model>
<model>
<modelname>name2</modelname>
<version>....</version>
</model>
</carmake>
and I wrote for the first select box:
$(xml).find('carmake').each(function(){
var make = $(this).find('makename').text();
select.append("<option value='"+make+"'>"+make+"</option>");
});
and for the second box all i did:
var e = document.getElementById("selectbox1").options[e.selectedIndex].value;
myXML = $(xml).find("carmake").filter(function() {
return $(this).find('makename').text() == e;
});
Can anybody tell me how to finish the second box or does anybody have a
better idea ?

No comments:

Post a Comment