473,408 Members | 2,839 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

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
Sep 7 '08 #1
12 1755
acoder
16,027 Expert Mod 8TB
The second table has been (incorrectly) nested in the first.

Please use code tags when posting code. See How to ask a question.
Sep 8 '08 #2
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?
Sep 9 '08 #3
acoder
16,027 Expert Mod 8TB
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?
Sep 9 '08 #4
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 :)
Sep 9 '08 #5
acoder
16,027 Expert Mod 8TB
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.
Sep 9 '08 #6
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.
Sep 9 '08 #7
acoder
16,027 Expert Mod 8TB
One way it could work is that you display the message textarea without a header underneath the other three columns on its own.
Sep 10 '08 #8
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?
Sep 10 '08 #9
acoder
16,027 Expert Mod 8TB
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?
Sep 10 '08 #10
yeh that would be perfect... how would u code it compared to what i have?
Sep 10 '08 #11
acoder
16,027 Expert Mod 8TB
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.
Sep 10 '08 #12
sound one ill try that now. Thanks for the help.
Sep 10 '08 #13

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: ojvm | last post by:
ok. thanks again for the time spend reading this. this code adds 2 controls in html form but it places in top of the form. i want this control1 control2 control1 control2 control1 ...
16
by: Philippe C. Martin | last post by:
Hi, I am trying to change the data in a form field from python. The following code does not crash but has no effect as if "form" is just a copy of the original html form. Must I recreate the...
5
by: patricksabourin | last post by:
On my site, I have 2 methods of displaying my data: 1) HTML form with select-option element. (Jump to different page when clicking "Go" button" 2) HTML table with a hyperlink. What I would...
0
by: bp_jobemail | last post by:
I'm trying to use PHP to wrap the output of an HTML form before it goes into a precompiled C cgi script. Essentially, the company that I work for uses a purchased precompiled c program for their...
2
w33nie
by: w33nie | last post by:
This html form that I'm using works fine, apart from that it never ends up sending any information through to my designated email. Does anyone see a problem in my code? <form...
2
by: Jibran | last post by:
I need some help with extra spaces in HTML form. There is a big white space appearing at the center of the HTML form that I am designing even though there is no <br> tags been used: ...
1
by: jpenguin | last post by:
This should be simple, but I'm stuck <?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db('joshdye', $con);
2
luckysanj
by: luckysanj | last post by:
I have problem on creating academic table. I need to input from html form to different academic table. But how to create academic table for my requirement. I have different leve of student....
4
by: beary | last post by:
Hi Being tested using FF 3 on WAMP server. I have spent a number of hours trying to figure this out myself. I have a html form using table cells and had a request to enable the arrow keys on a...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...
0
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...

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.