Hi to all

I would like to create a dynamic button which adding new rows to my table and then sending it to PHP, I manage to create the JS function but after the rows have been added its not apearing the HTML code and by that I can't send it to PHP by form. here the code:

function Addline(ObjId,ItemAdd){
    /*
     *Addin One Line to the table 
     **/
    var Elem = document.getElementById(ObjId);
    var row = document.createElement("TR");
    var td1 = document.createElement("TD");
    var td2 = document.createElement("TD");
    var Input = document.createElement("input");
    var Items = document.getElementById(ItemAdd);
    Global_i_table++;//Global var for the RowsCount
    Input.setAttribute("name", "addition"+Global_i_table);


    var RowName = prompt("Insert Field name");
    while(RowName == "" || !isNaN(RowName)){
        alert("Invalid name");
        RowName = prompt("Insert Field name");
    }
    td1.appendChild(document.createTextNode(RowName));
    td2.appendChild (Input);

    row.appendChild(td1);
    row.appendChild(td2);
    Elem.appendChild(row);

    Items.value = Global_i_table;
}

thanks

Loudstil,

When you use javascript to manipulate the DOM directly (as with document.createTextNode() and el.appendChild() ), the changes are not reflected in the HTML.

The HTML (and hence whatever you see with "view page source") only exists to seed the DOM when the page is first loaded.

I think I'm right in saying that very early Newscape did keep the HTML up to date. As far as I am aware, no current browsers do so though some are supported by debug environments which go some way to helping you in this respect. I don't use a debugger so am unable to advise further - maybe someone else will be able to post something useful. I'm pretty certain that Daniweb regular shawnCPlus gave some good advice (more than) once.

Airshow

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.