Help | Site Map
Connecting Tech Pros Worldwide
Reply
 
LinkBack Thread Tools
  #1  
Old September 7th, 2008, 05:51 PM
Member
 
Join Date: Sep 2008
Posts: 36
Default 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
Reply
  #2  
Old September 8th, 2008, 01:21 PM
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 12,727
Default

The second table has been (incorrectly) nested in the first.

Please use code tags when posting code. See How to ask a question.
Reply
  #3  
Old September 9th, 2008, 04:23 PM
Member
 
Join Date: Sep 2008
Posts: 36
Default

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?
Reply
  #4  
Old September 9th, 2008, 04:29 PM
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 12,727
Default

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?
Reply
  #5  
Old September 9th, 2008, 05:38 PM
Member
 
Join Date: Sep 2008
Posts: 36
Default

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 :)
Reply
  #6  
Old September 9th, 2008, 08:49 PM
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 12,727
Default

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.
Reply
  #7  
Old September 9th, 2008, 09:39 PM
Member
 
Join Date: Sep 2008
Posts: 36
Default

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.
Reply
  #8  
Old September 10th, 2008, 11:54 AM
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 12,727
Default

One way it could work is that you display the message textarea without a header underneath the other three columns on its own.
Reply
  #9  
Old September 10th, 2008, 02:22 PM
Member
 
Join Date: Sep 2008
Posts: 36
Default

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?
Reply
  #10  
Old September 10th, 2008, 02:57 PM
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 12,727
Default

No, I meant something like this:

Expand|Select|Wrap|Line Numbers
  1. |   1   |    |   2   |   3   |  
  2. inputs
  3. | :::::::::::::::::::::::::::::|
  4.  
2nd pass

Expand|Select|Wrap|Line Numbers
  1. |   1  |   |   2   |   |   3   |  
  2. inputs
  3. |::::::::::::::::::::::::::::::|
  4. inputs
  5. |::::::::::::::::::::::::::::::|
  6.  
Is that OK?
Reply
  #11  
Old September 10th, 2008, 03:49 PM
Member
 
Join Date: Sep 2008
Posts: 36
Default

yeh that would be perfect... how would u code it compared to what i have?
Reply
  #12  
Old September 10th, 2008, 05:45 PM
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 12,727
Default

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.
Reply
  #13  
Old September 10th, 2008, 07:03 PM
Member
 
Join Date: Sep 2008
Posts: 36
Default

sound one ill try that now. Thanks for the help.
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