September 08, 2008, 03:39:50 *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Revenue sharing launched. This is offered as a "thank you" for being a member of webmasterstalks.com community! If you have an Adsense/Yahoo publisher account then you can start right away !
 
  Home   Forum   Help Search Directory Calendar Login Register    RSS 2.0 feedAtom feed


News
Revenue sharing launched. This is offered as a "thank you" for being a member of webmasterstalks.com community! If you have an Adsense/Yahoo publisher account then you can start right away !
Pages: [1]
  Print  
Author Topic:

Dynamic Table

 (Read 1048 times)
0 Members and 1 Guest are viewing this topic.
xulescu
Full Member
***

Points: 8
Offline Offline

Posts: 245


WWW
« on: September 15, 2006, 01:41:09 »

Hi,

 I just want to do a dynamic table. A table what contain input fields. For example my table start with 1 row 2 columns : <tr><td>Item1</td><td><input type="text" name="item1"></td></tr> . I want to have a button when is pressed to add to my table new rows liks : <tr><td>ItemX</td><td><input type="text" name="itemx"></td></tr>

Is that possible ?

Thankx
Logged



TheGodFather
Administrator
Hero Member
*****

Points: 202
Offline Offline

Posts: 2570



WWW
« Reply #1 on: September 16, 2006, 12:48:52 »

Hi,

 You just need to add your elements to a tbody. For example we have a table like:

Code:
<table>
<tbody id="myTable">
<tr>
<td></td> <!-- default cell, is not necesaly you can let the tbody empty-->
</tr>
</tbody>
</table>
<input type="hidden" value="0" id="theValue" /><a href='#' onclick=="javascript:addElement();">Add row</a>

and javascript function to add the element:

Code:
<script type="text/javascript">
<!--

function addElement()
{
var ni = document.getElementById('myTable');
var numi = document.getElementById('theValue');
var num = (document.getElementById("theValue").value -1)+ 2;
numi.value = num;
var divIdName = "my"+num+"Table";
var newdiv = document.createElement('tr');
newdiv.setAttribute("id",divIdName);
var newcell1= document.createElement('td');
var newcell2= document.createElement('td');
newcell1.innerHTML = "Content Cell 1 :&nbsp;"
newcell2.innerHTML = "Content Cell2 ";
newdiv.appendChild(newcell1);
newdiv.appendChild(newcell2);
ni.appendChild(newdiv);
}
//-->
</script>


I hope this helps ....

Regards
Logged

xulescu
Full Member
***

Points: 8
Offline Offline

Posts: 245


WWW
« Reply #2 on: September 17, 2006, 03:00:50 »

I will try tomorow morning to made this script work. Anyway thanks  !

Logged

Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.4 | SMF © 2006, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks

TinyPortal v0.9.7 © Bloc
Valid XHTML 1.0! Valid CSS!