1

I created a function that will loop through all elements in a dynamically cloned area so that the user can insert new information wherever they choose, or move the elements up and down. It seems to work fine everywhere but ie7. In ie7: when I add a row- the row adds, but deletes all rows after it (if it's not the last row); when i try to delete a row that was dynamically created- the row will not delete. I know the click event of the delete button is being fired, and is showing the correct id in the test alert I put in.

//to insert a new row
$('#clone_').clone(true).attr({
    id:'row_'  + newID
    }).insertBefore('#tbl_row');    

// to delete a row:
alert(id);///just wanted to point out this is correct
$('#' + id).remove();

//to renumber the rows after remove or insert
for (i = newrow; i < lastrow; i++){
  renumberSection(i, i+1, 0);
}


function renumberSection(numero, numero_swap, numero_temp){
//temporarily name the row to be swapped
$('#row_'+ numero_swap).attr('id','row_'+ numero_temp);

//change the selected line to the swapped line number
$('#row_'+ numero).attr('id','row_'+ numero_swap);

//change the swapped line to the selected line number
$('#row_'+ numero_temp).attr('id','row_'+ numero).insertBefore('#row_'+ numero_swap); //sometimes it's insertAfter - but i'm trying to simplify the code

}
3
  • Why do you need to give IDs to each row? Give them a class and reference them by their current position using .row:eq(position).
    – Barmar
    Jul 8, 2013 at 19:50
  • i have to dynamically give them names so when i submit the form (asp) i can loop through them. Because of that I just change id to be the same as name. Is there a reason I shouldn't be doing that?
    – tree
    Jul 8, 2013 at 19:55
  • I don't know ASP, but in PHP we give them names like name[] and PHP automatically turns them into an array. It's not necessary to give them explicit numbers in the HTML, and they don't need IDs.
    – Barmar
    Jul 8, 2013 at 19:58

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.