[Greasemonkey] Inserting Row in Table

A. Alfred Ayache alfred at lastbyte.ca
Sun May 28 19:58:19 EDT 2006


OK, here's how I ended up doing it:

 >>>
function makeRow() {
	newrow.setAttribute("class", 'bgtbllgreen');
	var aNew = new Array();
	for (i = 0; i < 18; i++) {
		var newEl = document.createElement('td');
		newEl.setAttribute('class', 'tabletitle3');
		newrow.appendChild(newEl);
		aNew[i] = newEl;
	}
	return(aNew);
}

	var newrow = document.createElement('tr');
	aNew = makeRow();
	aNew[1].setAttribute('colspan', '5');
	aNew[1].setAttribute('align', 'left');
	aNew[1].appendChild(document.createTextNode('Total IN(' + arr['IN'][ARR_CNT] + 
') + OG(' + arr['OG'][ARR_CNT] + ')'));
	aNew[6].setAttribute('align', 'right');
	aNew[6].appendChild(document.createTextNode(makeMin(arr['IN'][ARR_SUM] + 
arr['OG'][ARR_SUM])));
	
	var lastrow = rows[rows.length - 1];
	lastrow.parentNode.insertBefore(newrow, lastrow);

	var newrow = document.createElement('tr');
	aNew = makeRow();
	aNew[1].setAttribute('colspan', '5');
	aNew[1].setAttribute('align', 'left');
	aNew[1].appendChild(document.createTextNode('Total CF(' + arr['CF'][ARR_CNT] + 
')'));
	aNew[6].setAttribute('align', 'right');
	aNew[6].appendChild(document.createTextNode(makeMin(arr['CF'][ARR_SUM])));
	
	lastrow.parentNode.insertBefore(newrow, lastrow);
<<<

The makeRow() function needed to produce two outputs, newrow and aNew.  So I 
compromised by creating newrow outside of the function and returning aNew.  If 
anyone has a better way of doing this, I'm keen to hear about it.

Thanks,

A. Alfred Ayache
http://lphs76.ca             - Reunion community
http://www.rentersPlus.com   - Apartment Search
http://www.lastbyte.ca       - Web Design, eCommerce, PHP/MySQL, Java, Oracle


More information about the Greasemonkey mailing list