tags:

views:

57

answers:

1

Hello, I need to add a row to a table.I am using jQuery to add the row.But i my Add() function everyhing is working fine except that the blur function for the input fild "txtQuantity" is not getting triggered for the newly added row.Here is my function,

function Add()
{
var rowPart = $('#trPart0').clone(true).show().insertAfter('#tblPart tbody>tr:last');   
var index = document.getElementById("hdnMaxPartId").value;   
$("#tblPart tbody>tr:last").attr("id", "trPart" + index);
$("td:eq(0) img", rowPart).attr("id", "imgPartDelete" + index).attr("onclick", "");  
$("td:eq(1) input:eq(0)", rowPart).attr("id", "hdnWODefPartId" + index);
$("td:eq(1) input:eq(1)", rowPart).attr("id", "hdnPartCost" + index); 
$("td:eq(1) input:eq(3)", rowPart).attr("id", "txtPart" + index).attr("name",     "txtPart" + index).attr("onkeyup", "");  
$("td:eq(2) input", rowPart).attr("id", "txtQuantity" + index).attr("onblur", "");
$("td:eq(3) div", rowPart).attr("id", "divPartCost" + index);      
$("td:eq(4) div", rowPart).attr("id", "divPartUnit" + index);   

$("#imgPartDelete" + index).unbind().bind('click', function() {
        DeletePart(index);
    }
 ); 

 $("#txtPart" + index).unbind().bind('keyup', function() {          
        ajax_showOptions(this,"getPartForAC",event,2,"replace","div_part_list"+index);
    }
 ); 
 $("#txtQuantity" + index).unbind().bind('blur', function() {   
        ChangeClassForObject(this,"clsSpText_blur");          
        CalculateCost(index,this,"divPartCost"+index);            
    }
 );     

}
A: 

You might try to replace this line:

$("td:eq(2) input", rowPart).attr("id", "txtQuantity" + index).attr("onblur", "");

with

$("td:eq(2) input", rowPart).attr("id", "txtQuantity" + index).removeAttr("onblur");

But then again, you're acting just in the rowPart fragment, but you're .bind() function calls the DOM element txtQuantity. Looks confusing, do you append rowPart anywhere If not, none of those .bind() methods will match.

jAndy