help with onclick - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

help with onclick

tklinetkline Posts: 7Member
I have created a web page with a table that needs to add a row when the Add Row button is clicked. How do I capture the click event and do a loop to create another row in the table?

Thanks for the help!

Comments

  • WeirdofreakWeirdofreak Posts: 439Member
    [code]

    function addrow() {
    with (document)
    var table = (getElementById)? getElementById('table') : all['table'];

    table.addRow();
    }[/code]

    I haven't tested that, and I may have done some things I shouldn't, but it should give you the general idea.
  • tklinetkline Posts: 7Member
    : [code]
    :
    : function addrow() {
    : with (document)
    : var table = (getElementById)? getElementById('table') : all['table'];
    :
    : table.addRow();
    : }[/code]
    :
    : I haven't tested that, and I may have done some things I shouldn't, but it should give you the general idea.
    :

    I got this code to work but how do I add a check box not just text to the table?
    td1.appendChild(document.createTextNode("want a check box here"))
    Thanks!


    [code]
    function addRow(id){
    var tbody = document.getElementById
    (id).getElementsByTagName("TBODY")[0];
    var row = document.createElement("TR")
    var td1 = document.createElement("TD")
    td1.appendChild(document.createTextNode("column 1")) //how do I get a check box or a text field?
    var td2 = document.createElement("TD")
    td2.appendChild (document.createTextNode("column 2"))
    row.appendChild(td1);
    row.appendChild(td2);
    tbody.appendChild(row);
    }

    Add row





    row1_column1row1_column1
    [/code]

  • WeirdofreakWeirdofreak Posts: 439Member
    var check = document.createElement('input');
    check.setAttribute('type','check');
    td1.appendChild(check);

    I think that's the one.
Sign In or Register to comment.