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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create new set of HTML elements onClick of a button

Status
Not open for further replies.

venur

MIS
Aug 26, 2003
418
US
Hi,

In a HTML FORM I have some elements with in SPAN Tag and button "ADD" out side the span. When a user click on the button I want to create a new set of HTML elements that are in the SPAN tag and display it after the tag ie., I need to display the HTML fields twice with in the FORM.

Using innerHTML i can get the src with in the span tag, but the question is how do I display that back as elements so that the user can enter some data.

Code:
<html>

<head>
<title>Page</title>
</head>

<script language="javascript">
 function addNew(){
  var oElement = document.getElementById("org");
  var oInnerHTML = oElement.innerHTML;
  alert(oInnerHTML);
  
 }
</script>
<body>

<form method="POST" action>
  <span id="org">
   <table border="1" width="57%">
    <tr>
      <td width="50%"><span id="org0">Name:</span></td>
      <td width="50%"><span id="org3"><input type="text" name="T1" size="20"></span></td>
    </tr>
    <tr>
      <td width="50%"><span id="org1">Class:</span></td>
      <td width="50%"><span id="org4"><select size="1" name="D1">
      <option>One</option>
      <option>Two</option>
      <option>Three</option>
      </select></span></td>
    </tr>
    <tr>
      <td width="50%"><span id="org2">Number :</span></td>
      <td width="50%"><span id="org5"><input type="text" name="T2" size="20"></span></td>
    </tr>
    <tr>
      <td width="50%">&nbsp;</td>
      <td width="50%">&nbsp;</td>
    </tr>
  </table>
  </span>
<input type="button" value="Add " name="B3" onClick="addNew()">
</form>

</body>

</html>

I hope I am clear with what I am trying, Help is greatly appreciated.

Thanks
Venu
 
I suggest you change tack and use the correct DOM methods to append content to the table/form.

Cheers,
Jeff

[tt]Jeff's Page [/tt][tt]@[/tt][tt] Code Couch
[/tt]

What is Javascript? faq216-6094
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top