I have today problem with creating drop-down lists:
I have xml file like with such structure like this:
<resultset>
<row>
<field name="iso3166_2">AF</field>
<field name="country">AFGHANISTAN</field>
<field name="fixed">1.000</field>
<field name="mobile">1.300</field>
</row>
<row>
<field name="iso3166_2">US</field>
<field name="country">ALASKA</field>
<field name="fixed">0.100</field>
<field name="mobile">0.100</field>
</row>
</resultset>
And I would like to create drop-down list with country names in it (taken from those fields: <field name="country">...</field>
).
In addtion, after choosing country from this drop-down I would like to show variables from fixed
and mobile
from the same row
set as chosen country
in such span's:
<span id="mobile"><!-- mobile value --></span>
and in <span id="fixed"><!-- fixed value --></span>
I hope it is clear what I want to achieve, I was trying to solve it with answers from similiar question: dynamic load data from xml to drop down box with jquery but it's not working for me (I was doing something wrong I suppose). Please help!
Something like this should work:
In short, if you pull in your XML through AJAX, make sure it's treated as XML then you can treat it just like it's any other kind of document (with some caveats). Clearly this could be done with vanilla JavaScript but I find it easier to do with jQuery.