Jump to content


This topic is now archived and is closed to further replies.


Add content to page on click

Recommended Posts

Okay I want to add content to my page with the simple click of a link. I don't know if java can do this, but I thought that someone here might be able to help me do it.

Okay so the code looks like this;

[code]<table align="center" cellpadding="4" border="1">
      <td colspan="4" bgcolor="#3399FF" align="center"><b>UNION LEAGUE</b></td>
      <td bgcolor="#FFFFCC" align="center"><b>POS</b></td>
      <td bgcolor="#FFFFCC" align="center"><b>PLAYER</b></td>
      <td bgcolor="#FFFFCC" align="center"><b>STAT LINE</b></td>
      <form method="post" action="allstar.php?ADD=Y">
      <td bgcolor="#FFFFCC" align="center"><select name="pos[]">
      <td bgcolor="#FFFFCC" align="center">
            <input type="hidden" name="league[]" value="UL"><input type="text" name="player[]">
      <td bgcolor="#FFFFCC" align="center">
            <input type="text" name="stat[]">
      <td bgcolor="#FFFFCC" align="center">
            <a href="addnext">Add</a>
      <td colspan="4" align="center" valign="middle" bgcolor="#FFFFFF">
            <input type="submit" value="SUBMIT"></form>

When people click on the <a href="addnext">Add</a> I would like it to add another table row containg the same information as the previous one, and so forth so that users can add as many rosws as they want.

Not quite sure how to do this, anyone got any ideas?

Share this post

Link to post
Share on other sites
<title>JavaScript - Adding html elements dynamically</title>
<script type="text/javascript">
var numrows = 0;
function drawoptions()
  var tbl = document.getElementById("formtable");
  var targetnumrows = parseInt(document.getElementById("numoptions").value + "");
  // if they've selected to show more rows, then we add more rows
  if(targetnumrows > numrows)
      for(var i=0; i<targetnumrows - numrows; i++)
          var row = tbl.insertRow(tbl.rows.length);

          // create the name cell
          var cell = row.insertCell(0);
          var namefield = document.createElement("input");
          namefield.setAttribute("type", "text");
          namefield.setAttribute("id", "Name" + (numrows+i));
          namefield.setAttribute("value", "field id : Name" + (numrows+i));
          // create the email cell
          cell = row.insertCell(1);
          var emailfield = document.createElement("input");
          emailfield.setAttribute("type", "text");
          emailfield.setAttribute("id", "Email" + (numrows+i));
          emailfield.setAttribute("value", "field id : Email" + (numrows+i));
  // they've decided to show less rows, so we remove some
      for(var i=0; i<numrows - targetnumrows; i++)
          tbl.deleteRow(tbl.rows.length - 1);

  numrows = tbl.rows.length - 1;

window.onload = drawoptions;



<form method="post" action="someformhandler.aspx">
Enter your friends names and email addresses<br />

<input type='hidden'  id="numoptions" value=1>
<table id="formtable">
<tr><td colspan=2><a href="javascript:drawoptions();">add</td></tr>

<input type="submit" value="Save"  />




Share this post

Link to post
Share on other sites
It looks like this might work, now all I have to do is try to format it to fit my page.

Will this work with sending the form to a php script and not an aspx? Just wondering.


Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.