jack lanza
jack lanza

Reputation: 299

set javascript output in table structure

this is my code:-

var xml = "<results><result><Country_Code>IN</Country_Code><Country_Name>India</Country_Name><Region_Name>Gujarat</Region_Name><City>Rajkot</City><lat>13.060422</lat><lng>80.24958300000003</lng></result><result><Country_Code>KE</Country_Code><Country_Name>Kenya</Country_Name><Region_Name>Vihiga</Region_Name><City>Kakamega</City><lat>0.1182473</lat><lng>34.7334515999997</lng></result></results>";


xmlDoc = $.parseXML( xml );
$xml = $( xmlDoc );
function get_list(ls){
   $lat = $("#select").val();
   $lng = $("#value").val();
   $title = $xml.find( "lat:contains('"+$lat+"')" ).closest('result');    
   $t = $title.find("lng:contains('"+$lng+"')").closest('result');    
   $str = $t.contents().map(function(){
       return $(this).contents().eq(0).text();
   }).get().join(' ');

   $("#result").text($str);
}

i want to set my output in table structure like:-

<table>
<td>Country_Code: </td><td>IN</td><td><tr>
<td>Country_Name: </td><td>India</td><td><tr>
<td>Region_Name: </td><td>Gujarat</td><td><tr>
<td>City: </td><td>Rajkot</td><td><tr>
<td>lat: </td><td>13.060422</td><td><tr>
<td>lng: </td><td>80.24958300000003</td><td><tr>
</table>

as above i want to set my output as a table wise Please help me how to do this...
thanks...

Upvotes: 2

Views: 869

Answers (1)

tamilmani
tamilmani

Reputation: 591

In side the function u create the table and stored in one variable and append the variable where u want it.this is only example..

var table = '<table><tr><td>'+$title>+'</td><td>'+$t+'</td></tr></table>';

and append the table in one div

$("#divid").append(table);

Upvotes: 1

Related Questions