randomizertech
randomizertech

Reputation: 2329

Dynamic input table to dynamic label table in HTML Javascript

I am trying to make this function I used in my program before but instead of having input fields showing the data, I need it to show labels or text with the data so I can copy and paste it in Excel.

Here is the method:

    cnt=0;
function addRowReporte(tableID,nroColumna) {
    var table = document.getElementById(tableID);
    var rowCount = table.rows.length;
    var row = table.insertRow(rowCount);

    for(c=0;c<nroColumna;c++){

        var cell = row.insertCell(c);
        var element = document.createElement("input");
        element.type = "text";

        element.name = ct+"0"+c;
        element.size = "16";
        element.id = ct+"0"+c;

        cell.appendChild(element);
    }
    cnt++;
}

I tried changing the createElement("input") to label but it didn't work

The text or "value" of the field is later on called using this:

document.getElementById(id).value = rs.Fields(colu).Value;

As always, any help is greatly appreciated

Upvotes: 0

Views: 1740

Answers (1)

Bafsky
Bafsky

Reputation: 771

You can use text nodes to insert text directly into the table cells, like so...

cnt=0;
function addRowReporte(tableID,nroColumna) {
    var table = document.getElementById(tableID);
    var rowCount = table.rows.length;
    var row = table.insertRow(rowCount);

    for(c=0;c<nroColumna;c++){
        var cell = row.insertCell(c);
        var element = document.createTextNode("text goes here");

        cell.appendChild(element);
    }
    cnt++;
}

Upvotes: 1

Related Questions