| Author: Kundan Kumar Sinha 08 Sep 2008 | Member Level: Gold | Rating: Points: 6 |
Hi,
The Javascript function takes the value of text box. Using for loop creates the number of rows. Using innerHTML property of Div tag the table is being displayed.
Add the following Javascript function in Head section of your page, between Script tag
function ShowTable() { var show = document.getElementById("table"); var tableHead = "<Table Border='1' width='100%'>"; var tableBottom = "</table>"; var tableBody=""; var j; j = document.frm1.txtValue.value; for(var i = 0; i < j; i++) { tableBody = tableBody + "<tr><td>1</td><td>2</td><td>3</td><td>4</td><td>5</td></tr>"; } show.innerHTML = tableHead + tableBody + tableBottom ; }
Add the following code in the body section of your page.
<form name="frm1"> Number of Rows: <input type="text" name="txtValue"> </form> <input type=button name="shwTable" value="Show Table" onClick="javascript:ShowTable();"> <div id="table"></div>
Regards, Kundan
|
| Author: Kundan Kumar Sinha 08 Sep 2008 | Member Level: Gold | Rating: Points: 6 |
-
|