I want to insert a option tag with text and value from reading xml tags.
Here I want to insert <option value> Text</option> like this way below:
<option value[from each xml col1]> Text [from each xml col2] </option>
Here is the code:
var xml = ' <row id="1_2"> <col1>46.0</col1> <col2>Acting Allowance</col2> </row> <row > <col1>A1</col1> <col2>Allowance for 65 years plus</col2></row>',
xmlDoc = $.parseXML(xml),
$xml = $(xmlDoc);
$xml.find('col2').each(function () {
var option = $(this).text(), //i want to take text from each col2 as option text
value = $(this).attr('value'); //i want to take text from each col1 as option value
$("#selectID").append("<option value='" + value + "'>" + option + "</option>");
});
<select id="selectID"></select>
Please let me know for further information. Thanks.
<col2>doesnt' have a value ?<option >tag and text (not value) of col2 as a Text for<option >tag.thanks<row>in yourfindaction and the grabvalue/textfrom either<col1/col2>