Click here to Skip to main content
15,893,668 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HEllo Everyone,

I want to show the array Data in HTML Table.I have the try this as follow :
JavaScript
function arrayData() {
            debugger;
            var employee = [];
            employee = [{ Id: 1, Name: "Harshal", Age: 22 }
        , { Id: 2, Name: "Bill", Age: 44 }
        , { Id: 3, Name: "Thomas", Age: 32 }
        , { Id: 4, Name: "Austin", Age: 56}];



            //records get show in Textbox inside the Cells
            for (var index = 0; index < employee.length; index++) {
                $("#tbNames tr:last").after("<tr><td>" + employee[index].Id + "</td> <td>" +<input id="nameTextBox" type="text" value="+employee[index].Name+" />
                                                                            + "</td> <td>" + <input id="ageTextBox" type="text" value="employee[index].Age" /> + "</td> </tr>");
            }
        }
<pre lang="html">
</script>
<p>
   The Below Button will Fill the Data</p>
   <button id="clickButton">
       CLICK</button>
   <table id="tbNames" border="1">
       <tr>
           <th>
               ID
           </th>
           <th>
               NAME
           </th>
           <th>
               AGE
           </th>
       </tr>
       <!--    <tr>
           <td>
               put value here
           </td>
       </tr>-->
   </table>



Thanks in Advance
Harshal
Posted
Updated 24-Oct-14 3:41am
v6
Comments
Sinisa Hajnal 24-Oct-14 6:41am    
You're mixing <ul> and <tr> tags without having <table> tag...what gives?
R Harshal 24-Oct-14 6:48am    
Hi ALL/Sinsia,
I have updated the Code but no use ,I am not getting the Array data in HTMl TAble.

Please guide me.
R Harshal 24-Oct-14 7:22am    
Hi Team,
Please help me out .

Fixed - [Demo] Assign Array to HTML Table[^]

You need the properties from the Array like...
JavaScript
for (index = 0; index < employee.length; index++) {
    $("#tbNames tr:last").after("<tr><td>" + employee[index].Id + "</td><td>" + employee[index].Name + "</td><td>" + employee[index].Age + "</td></tr>");
}
 
Share this answer
 
Comments
R Harshal 24-Oct-14 8:01am    
Thanks Tadit
Welcome. :)
R Harshal 24-Oct-14 8:43am    
if i want to use textbox in cell .I have tried this
for (var index = 0; index < employee.length; index++) {
$("#tbNames tr:last").after("<tr><td>" + employee[index].Id + "</td> <td>" +<input id="nameTextBox" type="text" />
+ "</td> <td>" + $('#ageTextBox').val(employee[index].Age) + "</td> </tr>");
}

But it not works
Will anyone can guide me .
Thanks in Advance
What are you doing? Do you understand the code?
R Harshal 24-Oct-14 8:47am    
As i have updated the Question .
Check this fiddle[^]

It is using the array and uses functions for DOM manipulation.

If this helps please take time to accept the solution. Thank you.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900