Connecting Tech Pros Worldwide Help | Site Map

Cloning / creating new row to my 3 column table(noob btw!)

Member
 
Join Date: Sep 2008
Posts: 36
#1: Sep 5 '08
Hi guys this is my first post an ive only started to use HTML, PHP and mySQL so here goes.

The problem I am having is that i want a single line table to duplicate more lines of code when an onClick button is pressed. it basically goes

Staff name Wage hours worked
I:::::::I I:::::::::::::I I:::::::::::::::::I IButtonI

When the button is pressed i want the form table to change to
Staff name Wage hours worked
I:::::::I I:::::::::::::I I:::::::::::::::::I
I:::::::I I:::::::::::::I I:::::::::::::::::I IButtonI

and so on. I am storing staff name etc as an array so i can easily calculate totals. Is there a way to do this dynamically without having to show / hide or else using DOM?

Any help appreciated!
eWish's Avatar
Moderator
 
Join Date: Jul 2007
Location: Arkansas
Posts: 900
#2: Sep 5 '08

re: Cloning / creating new row to my 3 column table(noob btw!)


This will require the use of JavaScript or DHTML. Moving to JavaScript/DHTML/Ajax Forum.

--Kevin
RamananKalirajan's Avatar
Needs Regular Fix
 
Join Date: Mar 2008
Location: Chennai - India
Posts: 348
#3: Sep 5 '08

re: Cloning / creating new row to my 3 column table(noob btw!)


Hi hope this code will hep u out

[HTML]<html>
<head>
<script type="text/javascript">
function doThis()
{
var myTab = document.getElementById('myTable');
var row=myTab.rows.length;
var y=myTab.insertRow(row);

var a=y.insertCell(0);
var xx= document.createElement('input');
xx.type="text";
a.appendChild(xx);

var b=y.insertCell(1);
var xx= document.createElement('input');
xx.type="text";
b.appendChild(xx);

var c=y.insertCell(2);
var xx= document.createElement('input');
xx.type="text";
c.appendChild(xx);

}
</script>

</head>
<body>
<br/>
<input type="button" value="Add" onclick="doThis()">
<br/>
<table id="myTable" border="1" cellspacing="5" cellpadding="5">
<tr>
<th>Name</th>
<th>Wage</th>
<th>Hours Worked</th>
</tr>
</table>
</body>
</html>[/HTML]

Regards
Ramanan Kalirajan
Ferris's Avatar
Member
 
Join Date: Oct 2007
Location: Shanghai
Posts: 102
#4: Sep 5 '08

re: Cloning / creating new row to my 3 column table(noob btw!)


there's an example in W3 schools.
http://www.w3schools.com/js/tryit.as...able_insertrow

Regards.
Member
 
Join Date: Sep 2008
Posts: 36
#5: Sep 5 '08

re: Cloning / creating new row to my 3 column table(noob btw!)


Hey guys u wudnt believe how long ive searched the internet to find a solution to this... id say it approaching around 12hrs over a week ...

Your help is much appreciated and that coding works perfectly exactly wat i was looking for ... cheers.

I think im gona have to help a few ppl on this wen i finish my coursework to balance it out a bit :)
RamananKalirajan's Avatar
Needs Regular Fix
 
Join Date: Mar 2008
Location: Chennai - India
Posts: 348
#6: Sep 5 '08

re: Cloning / creating new row to my 3 column table(noob btw!)


Quote:

Originally Posted by micky125

Hey guys u wudnt believe how long ive searched the internet to find a solution to this... id say it approaching around 12hrs over a week ...

Your help is much appreciated and that coding works perfectly exactly wat i was looking for ... cheers.

I think im gona have to help a few ppl on this wen i finish my coursework to balance it out a bit :)


I am realy happy that you got the required thing. There is some difference between mine and the other expert who posted another link. Mine is Dom, the expert what he had given is using innerHTML. Understanding innerHTML is very easy. In future any doubts post it in the forum. I will be there trying to help u out.

Regards
Ramanan Kalirajan
Reply