populate xml in dropdown with jquery

abaksvekvuche

New Member
i want to populate a xml with jquery. i got the following code:jquery:\[code\] $.ajax({ type: "GET", url: "GHworkerType.xml", dataType: "xml", success: function (xml) { $(xml).find('type').each(function () { var id = $(this).attr('id'); var name = $(this).find('name').text(); var rate = $(this).find('rate').text(); $('<div id="link_' + id + '"></div>').html('<a href="' + name + '">' + type + '</a>').appendTo('#WorkerTypeDropDownList'); }); } });\[/code\]xml:\[code\]<?xml version="1.0" encoding="UTF-8" standalone="yes"?><worker> <type id=0> <name>Fitter, mechanical or electrician</name> <rate>75</rate> </type></worker>\[/code\]html:\[code\]<select id="WorkerTypeDropDownList"> <option>loading</option></select>\[/code\]how can i populate this xml now? i want the user to select one of the items and pass the value(rate) to a variable to my codebehind (C#). i also want to populate this xml to another dropdownlist. but in this case i want to change the rate. how can i get this to work?greetzTobiEDIT:this is the code which is running:js:\[code\]$.ajax({ type: "GET", url: "GHworkerType.xml", dataType: "xml", success: function (xml) { var select = $('#comboWorkerType'); $(xml).find('type').each(function () { type = $(this).find('type').text(); select.append("" + type + ""); id = $(this).attr('id'); name = $(this).find('name').text(); rate = $(this).find('rate').text();// alert(rate); $('<option>' + name + '</option>').html('<option' + type + '">' + name + '</option>').appendTo('#comboWorkerType'); }); // alert($('#comboWorkerType option:selected').text()); select.children(":first").text("Select worker type").attr("selected", true); }\[/code\]xml:\[code\]<type> <name>Fitter, mechanical or electrician</name> <rate>75</rate></type>\[/code\]html:\[code\]<select id="comboWorkerType" > <option>Select worker type</option></select>\[/code\]but i want to get the rate of the selected item to my codebehind. how can i get this to run?greetztobi
 
Back
Top