473,473 Members | 2,193 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

add & remove rows from table

I have written a script that adds a row to a table and moves the
values from the initial line into the new line

What I am now trying to do is add a button in each new row that will
allow me to delete the row created

I am having no luck doing this

if i add a button using createelement and assosiate code with it the
code executes when i create the row

any help would be much appreciated

script as follows:

<HTML><HEAD>
<TITLE>test</TITLE>
<script LANGUAGE="JavaScript">
__uid = 0;

doc = document;

function addRowTo(id) {
var tbl = doc.getElementById(id);
//create a new row
var newrow = doc.createElement("TR");
var newcol , newinput;
newcol = doc.createElement("TD");
newcol.width = 200;
newinput = doc.createElement("input");
newinput.name = "date";
newinput.size = 20;
newinput.value = doc.main.date.value
newcol.appendChild(newinput);
newrow.appendChild(newcol);

newcol = doc.createElement("TD");
newcol.width = 200;
newinput = doc.createElement("input");
newinput.name = "start"+__uid;
newinput.size = 20;
newinput.value = doc.main.start.value
newcol.appendChild(newinput);
newrow.appendChild(newcol);

newcol = doc.createElement("TD");
newcol.width = 200;
newinput = doc.createElement("input");
newinput.name = "end"+__uid;
newinput.size = 20;
newinput.value = doc.main.end.value
newcol.appendChild(newinput);
newrow.appendChild(newcol);
tbl.appendChild(newrow);
__uid++;
document.main.date.value = '';
document.main.start.value = '';
document.main.end.value = '';

document.main.date.focus();
}

</script>
</HEAD>
<body>
<form name="main" method='post'>
<table id="tbl1">
<tbody id="tbl1body">
<td>DATE<td>START<td>END
<tr>
<td><input type='text' name='date' size=10 maxlength=200 value=""/>
<td><input type='text' name='start' size=10 maxlength=200 value=""/>
<td><input type='text' name='end' size=10 maxlength=200 value=""/>
<td>
<a href="#" onClick="addRowTo('tbl1body')">
<img border=0 src="/images/add.gif"></a>
</table>
</form></html>
Jul 20 '05 #1
2 21555
YD
Mike Solomon wrote:
I have written a script that adds a row to a table and moves the
values from the initial line into the new line

What I am now trying to do is add a button in each new row that will
allow me to delete the row created
I add changes in your code:
[...]
<HTML><HEAD>
<TITLE>test</TITLE>
<script LANGUAGE="JavaScript">
__uid = 0;

doc = document;

function delElem(elemToDel){
if(!elemToDel)return;
elemToDel.parentNode.removeChild(elemToDel);
}
function addRowTo(id) {
var tbl = doc.getElementById(id);
//create a new row
var newrow = doc.createElement("TR");
var newcol , newinput;
newcol = doc.createElement("TD");
newcol.width = 200;
newinput = doc.createElement("input");
newinput.name = "date";
newinput.size = 20;
newinput.value = doc.main.date.value
newcol.appendChild(newinput);
newrow.appendChild(newcol);

newcol = doc.createElement("TD");
newcol.width = 200;
newinput = doc.createElement("input");
newinput.name = "start"+__uid;
newinput.size = 20;
newinput.value = doc.main.start.value
newcol.appendChild(newinput);
newrow.appendChild(newcol);

newcol = doc.createElement("TD");
newcol.width = 200;
newinput = doc.createElement("input");
newinput.name = "end"+__uid;
newinput.size = 20;
newinput.value = doc.main.end.value
newcol.appendChild(newinput);
newrow.appendChild(newcol);
newcol = doc.createElement("TD");
newcol.width = 200;
newinput = doc.createElement("input");
newinput.setAttribute("type","button");
newinput.name = "destroy"+__uid;
newinput.value="Clear";
newinput.onclick=new Function ("delRow(document.getElementById('row"+__uid+"')); ");
newcol.appendChild(newinput);
newrow.appendChild(newcol);

tbl.appendChild(newrow);
__uid++;

etc.


HTH

--
Y.D.
Jul 20 '05 #2
"YD" <yd*****@free.fr> wrote in message news:<3f***********************@news.free.fr>...
Mike Solomon wrote:
I have written a script that adds a row to a table and moves the
values from the initial line into the new line

What I am now trying to do is add a button in each new row that will
allow me to delete the row created
I add changes in your code:


thanks for this - i made a 2 changes to make it work for me

see below

snip ...

function delElem(elemToDel){
if(!elemToDel)return;
elemToDel.parentNode.removeChild(elemToDel);
}
function addRowTo(id) {
var tbl = doc.getElementById(id);
//create a new row
var newrow = doc.createElement("TR"); newrow.id = "row"+__uid;
var newcol , newinput;
newcol = doc.createElement("TD");
newcol.width = 200;
newinput = doc.createElement("input");
newinput.name = "date";
newinput.size = 20;
newinput.value = doc.main.date.value
newcol.appendChild(newinput);
newrow.appendChild(newcol);

newcol = doc.createElement("TD");
newcol.width = 200;
newinput = doc.createElement("input");
newinput.name = "start"+__uid;
newinput.size = 20;
newinput.value = doc.main.start.value
newcol.appendChild(newinput);
newrow.appendChild(newcol);

newcol = doc.createElement("TD");
newcol.width = 200;
newinput = doc.createElement("input");
newinput.name = "end"+__uid;
newinput.size = 20;
newinput.value = doc.main.end.value
newcol.appendChild(newinput);
newrow.appendChild(newcol);
newcol = doc.createElement("TD");
newcol.width = 200;
newinput = doc.createElement("input");
newinput.setAttribute("type","button");
newinput.name = "destroy"+__uid;
newinput.value="Clear";
newinput.onclick=new Function ("delRow(document.getElementById('row"+__uid+"')); ");

newinput.onclick=new Function
("delElem(document.getElementById('row"+__uid+" ') , __uid);");
newcol.appendChild(newinput);
newrow.appendChild(newcol);

tbl.appendChild(newrow);
__uid++;

etc.


HTH

Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: El Diablo | last post by:
Hi there, I'm trying dynamically generate extra rows in a table. So far this achieves this task within the tHead segment: theTable.tHead.appendChild(document.createElement('TR')) ....but...
4
by: rajender_4 | last post by:
Hi techies I have set up a Transaction replication from My Primary Server to Secondary Server on Orders table. Thousand of records gets inserted on Orders every hour which get replicated...
2
by: Mike | last post by:
My page populates a table with a list of names and other information from a JavaScript object. I receive changes (adds, change & delete) to that list, convert it into a JavaScript object. I do...
8
by: Mike | last post by:
Hello, I have a few rather urgent questions that I hope someone can help with (I need to figure this out prior to a meeting tomorrow.) First, a bit of background: The company I work for is...
1
by: ratnakarp | last post by:
Hi, I have a search text box. The user enters the value in the text box and click on enter button. In code behind on button click i'm writing the code to get the values from the database and...
1
by: John_H | last post by:
Re: ASP.NET 2.0 I would like suggestions or code examples on how to collect a variable length list of input data (item# & item quantity specifically). I thought that I could accomplish this...
3
by: Niyazi | last post by:
Hi all, I have a dataTable that contains nearly 38400 rows. In the dataTable consist of 3 column. column 1 Name: MUHNO column 2 Name: HESNO Column 3 Name: BALANCE Let me give you some...
7
by: Susan Mackay | last post by:
I have a data table that is connected to a database table with a data adapter in the 'standard' manner. However I want to be able to remove selected rows from the data table (i.e. no longer...
4
by: Jane T | last post by:
I appreciate how difficult it is to resolve a problem without all the information but maybe someone has come across a similar problem. I have an 'extract' table which has 1853 rows when I ask for...
5
by: Romulo NF | last post by:
Greetings, I´m back here to show the new version of the drag & drop table columns (original script ). I´ve found some issues with the old script, specially when trying to use 2 tables with...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.