Note that there are some explanatory texts on larger screens.

plurals
  1. POpopulate xml in dropdown with jquery
    text
    copied!<p>i want to populate a xml with jquery. i got the following code:</p> <p>jquery:</p> <pre><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(); $('&lt;div id="link_' + id + '"&gt;&lt;/div&gt;').html('&lt;a href="' + name + '"&gt;' + type + '&lt;/a&gt;').appendTo('#WorkerTypeDropDownList'); }); } }); </code></pre> <p>xml:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt; &lt;worker&gt; &lt;type id=0&gt; &lt;name&gt;Fitter, mechanical or electrician&lt;/name&gt; &lt;rate&gt;75&lt;/rate&gt; &lt;/type&gt; &lt;/worker&gt; </code></pre> <p>html:</p> <pre><code>&lt;select id="WorkerTypeDropDownList"&gt; &lt;option&gt;loading&lt;/option&gt; &lt;/select&gt; </code></pre> <p>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#). </p> <p>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?</p> <p>greetz</p> <p>Tobi</p> <p>EDIT:</p> <p>this is the code which is running:</p> <p>js:</p> <pre><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); $('&lt;option&gt;' + name + '&lt;/option&gt;').html('&lt;option' + type + '"&gt;' + name + '&lt;/option&gt;').appendTo('#comboWorkerType'); }); // alert($('#comboWorkerType option:selected').text()); select.children(":first").text("Select worker type").attr("selected", true); } </code></pre> <p>xml:</p> <pre><code>&lt;type&gt; &lt;name&gt;Fitter, mechanical or electrician&lt;/name&gt; &lt;rate&gt;75&lt;/rate&gt; &lt;/type&gt; </code></pre> <p>html:</p> <pre><code>&lt;select id="comboWorkerType" &gt; &lt;option&gt;Select worker type&lt;/option&gt; &lt;/select&gt; </code></pre> <p>but i want to get the rate of the selected item to my codebehind. </p> <p>how can i get this to run?</p> <p>greetz</p> <p>tobi</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload