javascript - Need to store JSON data in tabular form and to store it in a text field of a specif form -


i have create tabular form of data getting field in json format. when writing below code code works fine in mozilla showing error in ie. , need store value in textfield. please help.

suva.js

var data =[ {     "id" : "1",     "name" : "sh",     "workphone" : "0804568944",     "department" : "1",     "location" : "dfd",     "pickup" : "1" }, {     "id" : "2",     "name" : "sdfg",     "workphone" : "0804562255",     "department" : "ss",     "location" : "2",     "pickup" : "2" }, {     "id" : "2",     "name" : "sdfg",     "workphone" : "0804562255",     "department" : "ss",     "location" : "2",     "pickup" : "2" }, {     "id" : "2",     "name" : "sdfg",     "workphone" : "0804562255",     "department" : "ss",     "location" : "2",     "pickup" : "2" }, {     "id" : "2",     "name" : "sdfg",     "workphone" : "0804562255",     "department" : "ss",     "location" : "2",     "pickup" : "2" }, {     "id" : "2",     "name" : "sdfg",     "workphone" : "0804562255",     "department" : "ss",     "location" : "2",     "pickup" : "2" }];  function gettemplatedata(){  var tbl = document.createelement("table");  //header var hdr = document.createelement("tr");  for(var lbl in data[0]) {     var th = document.createelement("th");     th.innerhtml = lbl;     th.style.textdecoration = "underline";     hdr.appendchild(th); }   tbl.appendchild(hdr); document.body.appendchild(tbl);  //for each records for(var rec in data) {     var tr = document.createelement("tr");     for(var prop in data[rec])     {         var td = document.createelement("td");         td.innerhtml = data[rec][prop];         tr.appendchild(td);     }      tbl.appendchild(tr); }  var htmlstr = document.body.innerhtml; alert(htmlstr); return htmlstr;  } 

suva.html

<html>     <head>         <script type="text/javascript" src="suva.js"></script>     </head>     <body onload="gettemplatedata()">     </body> </html> 

function gettemplatedata(){ var content = '<table class="form-table"><tr><th>id</th>'; content += '<th>name</th>'; content += '<th>workphone</th>'; content += '<th>department</th>'; content += '<th>location</th>'; content += '<th>pickup</th>'; content += '</tr>'; document.body.innerhtml = content; (var = 0;i<data.length;i++)     {     $('.form-table tr:last').after('<tr><td>'+data[i].id+'</td><td>'+data[i].name+'</td> <td>'+data[i].workphone+'</td><td>'+data[i].department+'</td><td>'+data[i].location+'</td><td>'+data[i].pickup+'</td><tr>');     }  }  

Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -