0

Here is what I have so far: http://jsfiddle.net/JEAkX/1/

I am trying to get the appended cells to come after the last tr. Furthermore, I am attempting to change the appendTable(id) function so that the output cells have their content inside an <input> field like the original cells.

For the <input> addition I have tried:

Adding the input field code <input type='text' size='1' value='subset[i++]' /> at various point with no luck I also tried it in another location but changed the value to value='c'.

For append after last tr I have tried:

Using jQuery and .insertAfter('#alphabetTable tbody>tr:last') I added it to various parts of the cell.appendChild(document.createTextNode(subset[i++])); line but had no luck..probably the wrong placement?

I feel like I am sort of on the right track but lack the Javascript knowledge to know exactly where to insert the code and if surrounding code needs change.

2 Answers 2

0

It'll be easier with JQuery but here's a hint:

function appendTable(id)
{
    var tbody = document.getElementById(id).getElementsByTagName("tbody")[0];
    var i = 0;
    var html = '<tr>';
    for(i=0;i<4;i++){
        html += '<td><input type="text" size="1"/></td>';
    }
    html += '</tr>';

    tbody.innerHTML += html;
}
Sign up to request clarification or add additional context in comments.

Comments

0

Jquery:

var $tbody = $('#mytableid tbody:eq(0)');
var $tdLen = $('#mytableid tbody:eq(0) tr:eq(0) td').length; // cell length in row
$("<tr>").appendTo($tbody);
//append cells to row with input text
for (var i=0;i<$tdLen;i++){
    var inp = $("<input>").attr("type","text").attr("name","text"+i).val(i);
    var tdTemo = $("<td>");
    inp.appendTo(tdTemo);
    tdTemo.appendTo("tr:last");
}

this script will append row to table and add 4cells contain input type text :)

1 Comment

Omg, it told me about this response right after I posted:stackoverflow.com/questions/5254283/… do you think you could look at that one and tell me what you think?..I would prefer to delete this question as I was asking multiple questions in a poor way haha.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.