I am trying to create input fields in a table format after getting the info from the user regarding the number of rows. Number of columns remains constant as 2. I am attaching the script as below. I am not able to generate the input fields and throw some javaScript error. I am checking my code in IE6 version. Please let me know what went wrong. Thanks.
Code:<html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta http-equiv="Content-Style-Type" content="text/css"> <meta http-equiv="Content-Script-Type" content="text/javascript"> <style type="text/css"> .mytable { border:1px solid #000000; border-collapse:collapse; width:200px; } .mytable td{ background:#cccccc; border:1px solid #000000; } </style> <script type="text/javascript"> onload=function(){ var nrCols=2; var maxRows=4; var nrRows=maxRows+1; while(nrRows>maxRows){ nrRows=Number(prompt('How many rows? Maximum '+maxRows+' allowed.','')); } var root=document.getElementById('mydiv'); var tab=document.createElement('table'); tab.className="mytable"; var tbo=document.createElement('tbody'); var row, cell; var inpElem=document.createElement('<input type="text" name="mytextfield">'); for(var i=0;i<nrRows;i++){ row=document.createElement('tr'); for(var j=0;j<nrCols;j++){ cell=document.createElement('td'); //cell.appendChild(document.createTextNode(i+' '+j)) cell.appendChild('inpElem'); row.appendChild(cell); } tbo.appendChild(row); } tab.appendChild(tbo); root.appendChild(tab); } </script> </head> <body> <div id="mydiv"></div> </body> </html>



Reply With Quote
Bookmarks