I'm wanting to display numbers from a JSON array into a table.
I'm trying to get it to list 2 items then go to a new row but just can't get it to work. Can anyone offer any help? Here's what I have so far.
Im wanting it formatted with a new line every 2 entries.
Any help would be much appreciated.
I'm trying to get it to list 2 items then go to a new row but just can't get it to work. Can anyone offer any help? Here's what I have so far.
Code:
<html>
<head>
<title>Telephone List - Classic</title>
<script language="javascript" >
document.writeln("<h2>Telephone List - Classic</h2>");
var telephone = { "contact" : [
{ "Name" : "Mark", "Number" : 700 },
{ "Name" : "Luke", "Number" : 400 },
{ "Name" : "John", "Number" : 300 },
{ "Name" : "Matthew", "Number" : 600 }
],
}
var i = 0
document.writeln("<table width='90%' border='1'>");
document.writeln("<tr><td><b>Name</b></td><td><b>Number</b></td><td><b>Name</b></td><td><b>Number</b></td></tr>");
for(i=0;i<telephone.contact.length;i++)
{
document.writeln("<tr><td>"+ telephone.contact[i].Name+"</td>");
document.writeln("<td>"+ telephone.contact[i].Number+"</td>");
document.writeln("<td>"+ telephone.contact[i].Name+"</td>");
document.writeln("<td>"+ telephone.contact[i].Number+"</td>");
document.writeln("</tr>");
}
</script>
</table>
</head>
<body>
</body>
</html>
Im wanting it formatted with a new line every 2 entries.
Code:
Name Number Name Number
Mark 700 Luke 400
John 300 Matthew 600
Any help would be much appreciated.
Last edited: