The add table row is being added with: <p><a href="#" onclick="addTableRow('#table-1'); return false;">Add New</a></p>
No, your code does not work for me. It's exactly the same as the code I've been trying since last night, so no offense -- why would it work? ;) My problem here is that the id is not changing -- if you read what I wrote, I mentioned that I can see in the generated source that it is not changing. That's all that I need. Once that happens, the sortable stuff should work as well. On Mar 24, 5:31 am, Karl Swedberg <k...@englishrules.com> wrote: > Hi again, > > I don't see where you're actually calling the addTableRow function. > Also, did you look at the demo I put together for you? Did that one > work for you? Sometimes it helps to start simple and build up in order > to see where the problem is occurring. Which browser are you testing > in? Also, if the drag and drop stuff isn't being applied to the newly > appended row, the problem could be unrelated to the row's ID. See > these FAQs for details: > > http://docs.jquery.com/Frequently_Asked_Questions#Why_do_my_events_st...http://docs.jquery.com/Frequently_Asked_Questions#Why_doesn.27t_an_ev... > > --Karl > > ____________ > Karl Swedbergwww.englishrules.comwww.learningjquery.com > > On Mar 24, 2009, at 1:37 AM, rivkadr wrote: > > > > > I don't know why I need true in the function. I just copied the code > > from elsewhere ;) I am NOT a jquery (this is my first time using it) > > or JS expert, so am just trying to cobble something together for a > > work project, which is due by tomorrow. > > > I'm using > > this:http://www.isocra.com/2008/02/table-drag-and-drop-jquery-plugin/ > > > to allow the table rows to be sortable. I was originally using the > > id's for the tr tags that he had listed there in his example (i.e. > > just numbers), but changed them to tr1, tr2, and so on just now, since > > you say that numbers are not valid IDs . Doing that makes no > > difference -- if I add a new row to the table, and try to change the > > id, so that it will have an id different than the cloned row (and > > thereby, hopefully be sortable), it just isn't happening. (if I use a > > tool that lets me view the generated source, I can see that the ID has > > not changed) > > > My Current code: > > > ////javascript code > > > jQuery(document).ready(function() { > > jQuery('#table-1').tableDnD({ > > onDrop: function(table, row) { > > //alert(jQuery('#table-1').tableDnDSerialize()); > > }, > > dragHandle: "dragHandle" > > }); > > jQuery("#table-1 tr").hover(function() { > > jQuery(this.cells[0]).addClass('showDragHandle'); > > }, function() { > > jQuery(this.cells[0]).removeClass('showDragHandle'); > > }); > > }); > > > function addTableRow(table) > > { > > var clonedRow = jQuery(table + " tr:last").clone().attr({ id: > > 'tr13' }) ; > > jQuery(table).append(clonedRow); > > return true; > > > } > > > ///// my html > > <table id="table-1" cellspacing="0" cellpadding="2"><tr id="tr1"><td > > class="dragHandle" width="16"> </td> > > <td> <select id="athlete_ids[]" name="athlete_ids[]" class="pull- > > down"> > > <option value="0">None</option> > > <option value="9">, chris</option> > > <option value="517">, Willow</option> > > </select> > > </td> > > </tr> > > . > > . > > . > > (duplicated multiple times, with tr2, tr3, and so on as the ids) > > </table> > > > My specific test example has 12 rows in it. I'm trying to add the 13th > > row (hence why tr13 is currently hardcoded. I'll worry later about > > trying to figure out how many rows there are in the table. I just want > > to get the darn id to change, so I can sort any added rows!) > > > On Mar 23, 7:48 pm, Karl Swedberg <k...@englishrules.com> wrote: > >> A few things: > >> 1. Why do you need return true in the function? > >> 2. "13" is not a valid ID, > >> 3. you should probably be appending the row to a tbody, not the > >> table. > > >> Nevertheless, I just tried your first function and it seemed to work > >> fine for me: > > >>http://jsbin.com/ideju/edit > > >> Does that work for you? > > >> --Karl > > >> ____________ > >> Karl Swedbergwww.englishrules.comwww.learningjquery.com > > >> On Mar 23, 2009, at 10:11 PM, rivkadr wrote: > > >>> Am getting bloody from beating my head against the wall. I just want > >>> to be able to change the id of a table row that is cloned and > >>> appended > >>> to a table. This shouldn't be so hard, no? > > >>> Here's what I've tried: > > >>> function addTableRow(table) > >>> { > >>> var clonedRow = jQuery(table + " tr:last").clone().attr({ id: > >>> '13' }) ; > >>> jQuery(table).append(clonedRow); > >>> return true; > >>> } > > >>> OR > > >>> function addTableRow(table) > >>> { > >>> var clonedRow = jQuery(table + " tr:last").clone(); > >>> jQuery(clonedRow).attr("id", "13"); //yes, I want the id to be > >>> 13 > >>> jQuery(table).append(clonedRow); > >>> return true; > >>> } > > >>> Neither of the above works. Anyone got any help they can give me, > >>> please?