 | 
September 7th, 2008, 05:51 PM
| | Member | | Join Date: Sep 2008
Posts: 36
| | A trickier HTML Form create new table(s)
Hey guys, another part of program I am stuck at is to create an email storage / reference system. I need the first line to hold the basic info, from to address etc and then a second row to store the message and any comments in a text box. The problem I am having is that I put the two into different tables so when a new line is added it adds to both them. Is it possible to do this e.g to have on the second add to append it to the bottom table?
I To | | From | | Date | | Subject |
| Message | | onClick() |
Which would go to
I To | | From | | Date | | Subject |
| Message |
I To | | From | | Date | | Subject |
| Message | | onClick() |
And so on. Here is the code i have so far ....
[HTML]<html>
<head>
<script type="text/javascript">
function removeRowFromTable()
{
var tbl = document.getElementById('myTable');
var lastRow = tbl.rows.length;
if (lastRow > 2) tbl.deleteRow(lastRow - 1);
var tbl1 = document.getElementById('myTable1');
var lastRow1 = tbl1.rows.length;
if (lastRow1 > 2) tbl1.deleteRow(lastRow1 - 1);
}
</script>
<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";
xx.name="EmailFrom[]";
a.appendChild(xx);
var b=y.insertCell(1);
var xx= document.createElement('input');
xx.type="text";
xx.name="EmailTo[]";
b.appendChild(xx);
var c=y.insertCell(2);
var xx= document.createElement('input');
xx.type="text";
xx.name="EmailDate[]";
c.appendChild(xx);
var d=y.insertCell(3);
var xx= document.createElement('input');
xx.type="text";
xx.name="EmailSubject[]";
d.appendChild(xx);
var myTab1 = document.getElementById('myTable1');
var row1=myTab1.rows.length;
var z=myTab1.insertRow(row1);
var e=z.insertCell(0);
var xx= document.createElement('textarea');
xx.col="200"
xx.rows="5"
xx.name="Message[]";
e.appendChild(xx);
}
</script>
</head>
<body>
<br/>
<input type="button" value="Add" onclick="doThis()">
<input type="button" value="Remove" onClick="removeRowFromTable()">
<br/>
<table id="myTable" border="1" cellspacing="5" cellpadding="5">
<tr>
<th>From</th>
<th>To</th>
<th>Date</th>
<th>Subject</th>
</tr>
<table id="myTable1" border="1" cellspacing="5" cellpadding="5">
<tr>
<th>Message</th>
</tr>
</table>
</table>
</body>
</html>[/HTML]
Any help much appreciated
Last edited by acoder; September 8th, 2008 at 01:17 PM.
Reason: Added [code] tags
| 
September 8th, 2008, 01:21 PM
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 12,964
| |
The second table has been (incorrectly) nested in the first.
Please use code tags when posting code. See How to ask a question.
| 
September 9th, 2008, 04:23 PM
| | Member | | Join Date: Sep 2008
Posts: 36
| |
my apologies im fairly new to this forum but in future i will post with regards to the "how to..."
In relation to what you said do you mean that you cannot nest tables like this or that I have nested it wrongly but it can work.
what are your thoughts on this?
| 
September 9th, 2008, 04:29 PM
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 12,964
| |
I haven't tested your code, but I noticed that myTable1 is nested inside myTable after a row, but not inside a table cell. Did you mean to nest tables like that or was it supposed to be outside the main table?
| 
September 9th, 2008, 05:38 PM
| | Member | | Join Date: Sep 2008
Posts: 36
| |
No it is meant to be inside the table but im not 100% sure if it is the way to go... the real question im asking is can i have one table that will have two different rows of headers. e.g. can a table be
| 1 | | 2 | | 3 |
|input 1| | input2| |input3|
| 4 |
| input 4 |
then onclick will add another full two rows for input.
the reason y im looking this is ive been asked to store emails so correspondence can be viewed (along with alot of other info) with in the one system. The from, to and subject are all low character fields whereas the email can be quite large and so doing it
| 1 | | 2 | |3 | |4 | will not look good as input 4 is a text area around 60 by 5.
hope i have been able to clarify the problem a bit more :)
| 
September 9th, 2008, 08:49 PM
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 12,964
| |
How would you match up the rows? Say you have 3 rows. If the first three columns are separated from the message column, how will the users know which refers to which?
PS. to answer your question on whether it's possible, it is.
| 
September 9th, 2008, 09:39 PM
| | Member | | Join Date: Sep 2008
Posts: 36
| |
that was the problem... from the way the code works now it isnt the prettiest to look at... as a first step i have just attached it to another column at the end of the first three inputs but again it doesnt really look right. the only other way i can think of doing it is that on the first pass it will do as normal but then passes after this will add to the second table although headings will not be there. Have you any ideas on a better solution cus i am more r less a noob with html.
| 
September 10th, 2008, 11:54 AM
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 12,964
| |
One way it could work is that you display the message textarea without a header underneath the other three columns on its own.
| 
September 10th, 2008, 02:22 PM
| | Member | | Join Date: Sep 2008
Posts: 36
| |
That would still leave the problem that each new record would be stored under the headings and the message field would store underneath it...
| 1 | | 2 | 3 |
inputs
| :::::::::::::::::::::::::::::|
2nd pass
| 1 | | 2 | | 3 |
inputs
inputs
|::::::::::::::::::::::::::::::|
|::::::::::::::::::::::::::::::|
As I am appending to the table, is this was you mean?
| 
September 10th, 2008, 02:57 PM
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 12,964
| |
No, I meant something like this: - | 1 | | 2 | 3 |
-
inputs
-
| :::::::::::::::::::::::::::::|
-
2nd pass - | 1 | | 2 | | 3 |
-
inputs
-
|::::::::::::::::::::::::::::::|
-
inputs
-
|::::::::::::::::::::::::::::::|
-
Is that OK?
| 
September 10th, 2008, 03:49 PM
| | Member | | Join Date: Sep 2008
Posts: 36
| |
yeh that would be perfect... how would u code it compared to what i have?
| 
September 10th, 2008, 05:45 PM
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 12,964
| |
Instead of adding/nesting another table, just add another row to myTable with insertRow(). Set the colSpan to 3 to cover all columns. When deleting, delete two rows.
| 
September 10th, 2008, 07:03 PM
| | Member | | Join Date: Sep 2008
Posts: 36
| |
sound one ill try that now. Thanks for the help.
|  | | Thread Tools | Search this Thread | | | |
Posting Rules
| You may not post new threads You may not post replies You may not post attachments You may not edit your posts HTML code is Off | | | | | | 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 205,248 network members.
|