Forum: Ruby on Rails Inserting a new row into a table

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ed Schechter <> <schechtere@ (Guest)
on 2005-12-10 07:18
Am still fairly low on the Rails/Javascript learning curve, so pardon me
if i am missing something elementary--

Am trying to stick a new row at the end of a table in response to some
event.

My table looks like this:

<table id='originStops' class='stops'>
  <tr>
    <td><strong>Origin Stops</strong> </td>
    <td class="ListActions"><a href="#"
onclick="showPopWin('/location/select', 600, 450, add_origin_link);;
return false;">Add</a></td>
  </tr>
</table>

I want to add new row to this table.

My Prototype effort (pun, sort of), was to put in a div right before the
end of the table looking like this:

<div id='endOfOriginStops'></div>

and to have whatever Javascript run something like this:

new Insertion.Before('endOfOriginStops', '<tr><td>Bite me</td></tr>');

Didn't work.  (in IE6).  Either died quietly or gave some message about
'invalid target element for this operation'

Ultimately, ended up creating this script

		function ieAppendRow(tableName, rowText) {
			  var tbl = $(tableName);
			  var row = tbl.insertRow();

			  var cell = row.insertCell(0);
			  var textNode = document.createTextNode(rowText);
			  cell.appendChild(textNode);
		}

and calling it like

                 ieAppendRow('originStops', 'Bite me');

This works fine in IE6.  Doesn't do diddly in FireFox.

From a few threads I've found, I gather IE6 is rather quirky in how in
handles innerHTML, and have seen some illusions to the Prototype library
not handling this correctly.  Is this assertion correct?  Do I need to
bypass the library for this functionality, or am I missing something?

Thanks
Ed
This topic is locked and can not be replied to.