Help | Site Map
Connecting Tech Pros Worldwide
Reply
 
LinkBack Thread Tools
  #1  
Old September 5th, 2008, 01:36 AM
Member
 
Join Date: Sep 2008
Posts: 36
Default Cloning / creating new row to my 3 column table(noob btw!)

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!
Reply
  #2  
Old September 5th, 2008, 03:24 AM
eWish's Avatar
Moderator
 
Join Date: Jul 2007
Location: Arkansas
Posts: 834
Default

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

--Kevin
Reply
  #3  
Old September 5th, 2008, 06:00 AM
RamananKalirajan's Avatar
Familiar Sight
 
Join Date: Mar 2008
Location: Chennai - India
Age: 24
Posts: 236
Default

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
Reply
  #4  
Old September 5th, 2008, 08:51 AM
Ferris's Avatar
Member
 
Join Date: Oct 2007
Location: Shanghai
Age: 22
Posts: 102
Default

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

Regards.
Reply
  #5  
Old September 5th, 2008, 11:40 AM
Member
 
Join Date: Sep 2008
Posts: 36
Default

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 :)
Reply
  #6  
Old September 5th, 2008, 01:18 PM
RamananKalirajan's Avatar
Familiar Sight
 
Join Date: Mar 2008
Location: Chennai - India
Age: 24
Posts: 236
Default

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
Reply

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles