Long ago, I needed to populate a table content and in the table there shall be textboxes created on the fly. I wanted default values in my array to be appearing in my textboxes by default.
Here is the old javascript way within HTML.
<html> <head> <script language=javascript> var myCars=new Array("Saab","Volvo","BMW"); function loadData() { var t=document.getElementById("t1"); for (var i in myCars) { // Insert a row in the table at the last row var newRow = t.insertRow(t.rows.length); // Insert a cell in the row at index 0 var newCell = newRow.insertCell(0); var textBox=document.createElement("input"); textBox.type="text"; textBox.value=myCars[i]; newCell.appendChild(textBox); } } </script> </head> <body onload="loadData()"> <table id="t1" border=1> </table> </body> </html>