table.insertRow
and tableRow.insertCell
take, as their parameters, the index at which you wish to do the insertion. You are, instead, passing a string which contains your field values appended to an HTML BR
tag (a malformed one at that).
Кроме того, чтобы добавить текст к элементу необходимо создать текстовые узлы с document.createTextNode
и приложите те узлы к рассматриваемому элементу.
Наконец, седла
должен быть ребенком ряды
, не стол
. Так ваша линия, table.appendChild (седла)
по ошибке также.
Вне тех комментариев я не могу пойти далее. Я не уверен, что точно вы ищете в произведенной структуре таблицы. Это кажется мне, вы желаете один ряд с двумя колонками, но ответ Дхэрмена показывает, что он читает его как вы желающий многократные ряды. Рассмотрите обновление вашего вопроса с некоторым повышением, показывающим желаемый стол.
Edit: Using your comment for more information, I wrote the following code demo for you to try: http://jsfiddle.net/Kkb7n/ . For the sake of demonstration, I have it use the "task name" as the text content of the created cells.
Измененный JS в случае, если JSFiddle снижается:
var makeChart = function() {
var table = document.createElement('table'),
taskName = document.getElementById('taskname').value,
numDays = document.getElementById('days').value, //columns
howOften = document.getElementById('times').value, //rows
row,
r,
col,
c;
for (r = 0; r < howOften; r++) {
row = table.insertRow(-1);
for (c = 0; c < numDays; c++) {
col = row.insertCell(-1);
col.appendChild(document.createTextNode(taskName));
}
}
document.getElementById('holdTable').appendChild(table);
};