Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to create table rows dynamically in JS

Status
Not open for further replies.

sunw

Technical User
Sep 24, 2007
32
US
Experts,

I am rather new to javascript. I want to create an html page which can add rows dynamically based on a user input. I wrote a piece of code below. But I don't know how to correctly implement 'addRows()' to do the job.

Thanks for your help.

Code:
<html><head><title>Dynamica Form</title>
<script language="JavaScript">
  function addRows() {
    var userinput = document.getElementById('myid').value;
//    alert('userinput = ' + userinput);
  }
</script>
<style>
  .base { border: solid black 1px; width: 20%; }
</style>
</head>
<body>
<form name="myform" action="#" method="post">
How many rows you want?
<input name='myname' id='myid' type='text' value='1' size=2 onkeyup="addRows();">
<p>
<div class='base'>row1</div>
[COLOR=red]<!--since the default value is 1, we have ONE row originally. -->
<!-- How to add rows here dynamically? -->[/color]
<p>
<div><input type=submit> <input type=reset></div>
</form>
</body>
</html>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top