T
Ted Byers
The simplest logical way for my form to support the data model is to
use a table.
It is trivial if I hard code the number of rows in the table simply
by nesting an input control inside the <td> element. That is basic
HTML. Relatively trivial, and trivial to have my CGI program server
side to process the data entered. But there is no good reason to
hardcode the number of rows. Inevitably, the number of rows that may
be hard coded will be inadequate for some fo the data.
Here is what I came up with (by studying code snippets I found on the
web):
<script>var n = 0</script>
<script>
function addRow(id){
n++;
var tbody = document.getElementById(id).getElementsByTagName
("tbody")[0];
var row = document.createElement("tr");
var data1 = document.createElement("td");
var str1 = 'row' + n + 'Column1';
data1.appendChild(document.createTextNode(str1));
var data2 = document.createElement("td");
data2.appendChild (document.createTextNode('row' + n +
'Column2'));
var data3 = document.createElement("td");
data3.appendChild (document.createTextNode('row' + n +
'Column3'));
row.appendChild(data1);
row.appendChild(data2);
row.appendChild(data3);
tbody.appendChild(row);
}
</script>
Now I need to figure out how to change this so that each row consists
of three input fields rather than 3 plain text strings. That I need
to ask this may well reflect how little I know about Javascript and/or
the DOM, but if so, please provide me an URL to a document that will
fill in that gap in my knowledge.
An ancillary question is how I may determine, within my function, how
many rows are present in the table prior to adding the row (so I can
get rid of '<script>var n = 0</script>').
Thanks
Ted
use a table.
It is trivial if I hard code the number of rows in the table simply
by nesting an input control inside the <td> element. That is basic
HTML. Relatively trivial, and trivial to have my CGI program server
side to process the data entered. But there is no good reason to
hardcode the number of rows. Inevitably, the number of rows that may
be hard coded will be inadequate for some fo the data.
Here is what I came up with (by studying code snippets I found on the
web):
<script>var n = 0</script>
<script>
function addRow(id){
n++;
var tbody = document.getElementById(id).getElementsByTagName
("tbody")[0];
var row = document.createElement("tr");
var data1 = document.createElement("td");
var str1 = 'row' + n + 'Column1';
data1.appendChild(document.createTextNode(str1));
var data2 = document.createElement("td");
data2.appendChild (document.createTextNode('row' + n +
'Column2'));
var data3 = document.createElement("td");
data3.appendChild (document.createTextNode('row' + n +
'Column3'));
row.appendChild(data1);
row.appendChild(data2);
row.appendChild(data3);
tbody.appendChild(row);
}
</script>
Now I need to figure out how to change this so that each row consists
of three input fields rather than 3 plain text strings. That I need
to ask this may well reflect how little I know about Javascript and/or
the DOM, but if so, please provide me an URL to a document that will
fill in that gap in my knowledge.
An ancillary question is how I may determine, within my function, how
many rows are present in the table prior to adding the row (so I can
get rid of '<script>var n = 0</script>').
Thanks
Ted