• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 672
  • Last Modified:

insertCell not working in Firefox

Ok, here is probably a very easy question that I am completely spacing on.  I am trying to create a script that will dynamically create a table with Javascript.

function ins_row(tab) {
	newRow = tab.insertRow(-1);

function add_data(tab, val, spn, lnk, bld, clr) {
	if(val !== 0 && isEmpty(val)) {
		val = " ";
	lstRow = tab.rows.length - 1;
	newCell = tab.rows[lstRow].insertCell(-1);
	if(!isNaN(val)) {
		newCell.align = "right";
		val = addCommas(val.toFixed(2));
	if (lnk && lnk != "") {
		val = "<a href=" + lnk +" class=" + clr +">" + val + "</a>";
	if (bld) {
		val = "<b>" + val + "</b>";
	if (clr && clr != "") {
		newCell.style.color = clr;
	newCell.innerHTML = val;
	if (spn > 1) {
		newCell.colSpan = spn;

Open in new window

When I call the functions, I either errors in Firefox (IE execs the code just fine)

I have a table call out:
<table width=850 id=tabl name=tabl cellpadding=0 cellspacing=0 class=proc></table>

Open in new window

and the function calls:
add_data(tabl, 'text', 10, '', true, 'blue');

Open in new window

I have tried both leaving tabl unquoted, which gives me tabl undefined errors, and quoted, which give me tab.rows undefined.

Please help
  • 2
1 Solution
srfreemanincAuthor Commented:
I added the getElementById line to reference the table, and it worked.
Michel PlungjanIT ExpertCommented:
yes, sorry I was too busy to dig out the actual solution and apply it.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now