Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Class/Member function Counter

Status
Not open for further replies.

FugitivePuppeT

Programmer
Jan 24, 2008
5
US
Code:
function InputRow() {
    this.currentRow;
    this.rowCount;
}

InputRow.prototype.newColumn = function (nColInnerHTML) {
    var nCol = document.createElement('td');
    nCol.innerHTML = nColInnerHTML;
    this.currentRow.appendChild(nCol);
}

InputRow.prototype.newRow = function(inputColumns) {
    var newTR = document.createElement('tr');
    for (var i = 0; i <= inputColumns.length - 1; i++) {
        var tdNode = document.createElement('td');
        tdNode.setAttribute('align', 'center');
        tdNode.innerHTML = "<input type='text' id='" + inputColumns[i] + this.rowCount + "' name='" + inputColumns[i] + this.rowCount + "' class='" + inputColumns[i] + "' />";

        newTR.appendChild(tdNode);
    }
    this.rowCount++;
    alert(this.rowCount);
    this.currentRow = newTR;
    return newTR;
}

The only problem i am having is.. i was using a global _rowcount and of course it worked fine, counting up and such, but it obviously screwed the pooch with more than one instance of this object.

I am trying to use this.rowCount as my counter.

It keeps resetting to 0 every function call.
 
How are you calling the 'newColumn' and 'newRow' functions? Are you doing it within the context of an 'InputRow' object? Perhaps showing more code might help...

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top