Jump to content


Creating Dynamic Tables with Javascript


1 reply to this topic

#1 Lang

    Young Padawan

  • Members
  • Pip
  • 198 posts
  • Gender:Male
  • Location:Ontario, Canada

Posted 06 February 2009 - 07:40 PM

So I'm trying to create a table dynamically with Javascript.

function init(){
	data_table = document.getElementById('data_table');
	
	header_row = data_table.insertRow(0);
	
	header_cell = header_row.insertCell(0);
	header_cell.innerHTML = "First Name";
	header_cell.className = "headerCell";

	header_cell = header_row.insertCell(1);
	header_cell.innerHTML = "Last Name";
	header_cell.className = "headerCell";
	
	header_cell = header_row.insertCell(2);
	header_cell.innerHTML = "Student Number";
	header_cell.className = "headerCell";
	
	header_cell = header_row.insertCell(3);
	header_cell.innerHTML = "Postal Code";	
	header_cell.className = "headerCell";
	
	document.getElementById('data_table').appendChild(header_row);
}

That works in Firefox just fine, but not in Internet Explorer. I also tried instead of creating the table in HTML then referencing it by document.getElementById('data_table') by actually creating it with document.createElement("Table") and then both Firefox and Internet Explorer didn't like the code.

Internet Explorer is saying that the last line of the function has an error. Says object does not support this property or method.

Any help is appreciated.

#2 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 07 February 2009 - 01:52 PM

I remember having to do table modification like this back in the day, however, it has been so long that i will just refer you to where i learned how to do it:
http://www.quirksmod...eateDelete.html

Unfortunately, i can't find the exact page i referenced, it appears as though the site has been updated and that is the page that replaced the original...

Edit, similar reference:
http://www.quirksmod...ble_credel.html

Edited by rc69, 07 February 2009 - 01:57 PM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users