I have one page where i can duplicate of (i.e HTML tag ) using jquery.
To maintain the UI i have created the variable in which i have saved the HTML tag and i am sending it to server side using hidden field.But whenever receive the hidden field and i try to put that into <table> tag it appends
function AddDuplicateHR(count, rateid, CurrentBodyStructure) {
var Count_of_body = "";
$("#HRtblMain >tBody").each(function (index) {
if (Count_of_body == "") {
Count_of_body = 1;
}
else {
Count_of_body = parseInt(Count_of_body + 1);
}
});
var isChecked = false;
var lstCount = count;
if (confirm('Are you sure, you want to duplicate selected record?')) {
var varCount = Count_of_body;
//Created Duplicated Element
//$("#edithotelroomrate").find("#HRtblMain:first").
//alert($("#edithotelroomrate").find("#HRtblMain").length);
$("#edithotelroomrate").find('table[Id*=HRtblMain]').each(function () {
if ($(this).html().length == 0) {
$(this).remove();
}
});
if ($("#edithotelroomrate").find("#HRtblMain").find("#HRtblMain").length > 0) {
$("#edithotelroomrate").find("#HRtblMain").find("#HRtblMain").append($("#edithotelroomrate").find(".BaseBody" + count).clone(true).attr('id', 'HRbody' + varCount).attr("class", "BaseBody" + varCount));
}
else {
$("#edithotelroomrate").find("#HRtblMain").append($("#edithotelroomrate").find(".BaseBody" + count).clone(true).attr('id', 'HRbody' + varCount).attr("class", "BaseBody" + varCount));
}
// var varCount = Count_of_body;
// //Created Duplicated Element
// if ($("#edithotelroomrate").find("#HRtblMain").find("#HRtblMain").length > 0) {
// $("#edithotelroomrate").find("#HRtblMain").find("#HRtblMain").append($("#edithotelroomrate").find(".BaseBody" + count).clone(true).attr('id', 'HRbody' + varCount).attr("class", "BaseBody" + varCount));
// }
// else {
// $("#edithotelroomrate").find("#HRtblMain").append($("#edithotelroomrate").find(".BaseBody" + count).clone(true).attr('id', 'HRbody' + varCount).attr("class", "BaseBody" + varCount));
// }
var tbodyElement = $("#edithotelroomrate").find("#HRtblMain").find('#HRbody' + varCount);
//tbodyElement.attr("class", "BaseBody" + varCount);
tbodyElement.find("#HR_Validation_HRDateFrom" + count).attr("id", "HR_Validation_HRDateFrom" + varCount);
tbodyElement.find("#HR_Validation_HRDateTo" + count).attr("id", "HR_Validation_HRDateTo" + varCount);
//HR_Validation_HRDayType
tbodyElement.find("#HR_Validation_HRDayType" + count).attr("id", "HR_Validation_HRDayType" + varCount);
//HR_Validation_HRRateUnit
tbodyElement.find("#HR_Validation_HRRateUnit" + count).attr("id", "HR_Validation_HRRateUnit" + varCount);
tbodyElement.find("#HRDateFrom" + count).attr('id', 'HRDateFrom' + varCount);
tbodyElement.find("#HRDateTo" + count).attr('id', 'HRDateTo' + varCount);
tbodyElement.find("#HRtr" + count).attr('id', 'HRtr' + varCount);
tbodyElement.find("#daytype" + count).attr('id', 'daytype' + varCount);
tbodyElement.find("#rateunit" + count).attr('id', 'rateunit' + varCount);
tbodyElement.find("#HRSingleRoomRate" + count).attr('id', 'HRSingleRoomRate' + varCount);
tbodyElement.find("#HRDoubleRoomRate" + count).attr('id', 'HRDoubleRoomRate' + varCount);
tbodyElement.find("#HRSinglesathalfdbl" + count).attr('id', 'HRSinglesathalfdbl' + varCount);
tbodyElement.find("#HRisNEW" + count).attr('id', 'HRisNEW' + varCount);
tbodyElement.find("#hrtaxratetypeid" + count).attr('id', 'hrtaxratetypeid' + varCount);
tbodyElement.find("#hrtaxtype" + count).attr('id', 'hrtaxtype' + varCount);
//tbodyElement.find("#HRTaxRateAmount" + count).attr('id', 'HRTaxRateAmount' + varCount);
//tbodyElement.find("#HRTaxRefundable" + count).attr('id', 'HRTaxRefundable' + varCount);
//tbodyElement.find("#HRisIncludedInRate" + count).attr('id', 'HRisIncludedInRate' + varCount);
//tbodyElement.find("#HRisTaxRefundable" + count).attr('id', 'HRisTaxRefundable' + varCount);
tbodyElement.find("#hdnHRAddDatefrom" + count).attr('id', 'hdnHRAddDatefrom' + varCount);
tbodyElement.find("#hdnHRAddDateto" + count).attr('id', 'hdnHRAddDateto' + varCount);
//Tax Segments Of Hotel Room Service.
//iterate through the no of records from element from parent cloning and update the element id as per standards.
var No_of_TaxRecords_Existed = tbodyElement.find("#tblTaxMainRM tbody").length;
var CountForMultiple;
var CountForDelete = [];
for (var f = 0; f < No_of_TaxRecords_Existed; f++) {
CountForMultiple = f;
CountForDelete[f] = f;
tbodyElement.find("#HRTaxRateAmount" + f).change(function () {
Calculate_Total_TaxAmount(tbodyElement);
});
//Remove Duplicate binding
//TaxIncludedInRate
if (tbodyElement.find("#HRbody" + f).find("#HRTaxIncludedInRate_" + "HRbody" + count + "_" + count).length > 0) {
tbodyElement.find("#HRbody" + f).find("#HRTaxIncludedInRate_" + "HRbody" + count + "_" + count).attr("id", "HRTaxIncludedInRate_" + "HRbody" + varCount + "_" + f);
tbodyElement.find("#HRbody" + f).find("#HRTaxIncludedInRate_" + "HRbody" + varCount + "_" + f).attr('onclick', '').unbind('click');
tbodyElement.find("#HRbody" + f).find("#HRTaxIncludedInRate_" + "HRbody" + varCount + "_" + f).unbind('click');
tbodyElement.find("#HRbody" + f).find("#HRTaxIncludedInRate_" + "HRbody" + varCount + "_" + f).click(function () {
var CurrentId = $(this).attr("id");
DisableTaxAmounts(CurrentId, "HRbody" + varCount);
});
}
else {
if (tbodyElement.find("#HRbody" + f).find("#HRTaxIncludedInRate_" + "HRbody" + count + "_" + f).length > 0) {
tbodyElement.find("#HRbody" + f).find("#HRTaxIncludedInRate_" + "HRbody" + count + "_" + f).attr("id", "HRTaxIncludedInRate_" + "HRbody" + varCount + "_" + f);
tbodyElement.find("#HRbody" + f).find("#HRTaxIncludedInRate_" + "HRbody" + varCount + "_" + f).attr('onclick', '').unbind('click');
tbodyElement.find("#HRbody" + f).find("#HRTaxIncludedInRate_" + "HRbody" + varCount + "_" + f).unbind('click');
tbodyElement.find("#HRbody" + f).find("#HRTaxIncludedInRate_" + "HRbody" + varCount + "_" + f).click(function () {
var CurrentId = $(this).attr("id");
DisableTaxAmounts(CurrentId, "HRbody" + varCount);
});
}
}
//TaxType
if (tbodyElement.find("#HRbody" + f).find("#HRTaxTypeId_" + "HRbody" + count + "_" + count).length > 0) {
tbodyElement.find("#HRbody" + f).find("#HRTaxTypeId_" + "HRbody" + count + "_" + count).attr("id", "HRTaxTypeId_" + "HRbody" + varCount + "_" + f);
var PreviousValuesofTaxType = $("#HRTaxTypeId_HRbody" + count + "_" + f).val();
tbodyElement.find("#HRbody" + f).find("#HRTaxTypeId_" + "HRbody" + varCount + "_" + f).val(PreviousValuesofTaxType.toString());
tbodyElement.find("#HRbody" + f).find("#HRTaxTypeId_" + "HRbody" + varCount + "_" + f).unbind('change');
tbodyElement.find("#HRbody" + f).find("#HRTaxTypeId_" + "HRbody" + varCount + "_" + f).change(function () {
ValidationForTaxSystem($(this), "HRbody" + varCount);
});
}
else {
if (tbodyElement.find("#HRbody" + f).find("#HRTaxTypeId_" + "HRbody" + count + "_" + f).length > 0) {
tbodyElement.find("#HRbody" + f).find("#HRTaxTypeId_" + "HRbody" + count + "_" + f).attr("id", "HRTaxTypeId_" + "HRbody" + varCount + "_" + f);
var PreviousValuesofTaxType = $("#HRTaxTypeId_HRbody" + count + "_" + f).val();
tbodyElement.find("#HRbody" + f).find("#HRTaxTypeId_" + "HRbody" + varCount + "_" + f).val(PreviousValuesofTaxType.toString());
tbodyElement.find("#HRbody" + f).find("#HRTaxTypeId_" + "HRbody" + varCount + "_" + f).unbind('change');
tbodyElement.find("#HRbody" + f).find("#HRTaxTypeId_" + "HRbody" + varCount + "_" + f).change(function () {
ValidationForTaxSystem($(this), "HRbody" + varCount);
});
}
}
//TaxRate Type
if (tbodyElement.find("#HRbody" + f).find("#HRbody" + count + "_" + "HRTaxRateTypeId" + "_" + count).length > 0) {
tbodyElement.find("#HRbody" + f).find("#HRbody" + count + "_" + "HRTaxRateTypeId" + "_" + count).attr("id", "HRbody" + varCount + "_" + "HRTaxRateTypeId" + "_" + f);
var PreviouValues_TaxRateType = $("#HRbody" + count + "_" + "HRTaxRateTypeId" + "_" + f).val();
tbodyElement.find("#HRbody" + f).find("#HRbody" + varCount + "_" + "HRTaxRateTypeId" + "_" + f).val(PreviouValues_TaxRateType.toString());
tbodyElement.find("#HRbody" + f).find("#HRbody" + varCount + "_" + "HRTaxRateTypeId" + "_" + f).unbind('change');
tbodyElement.find("#HRbody" + f).find("#HRbody" + varCount + "_" + "HRTaxRateTypeId" + "_" + f).change(function () {
Calculate_Total_TaxAmount("HRbody" + varCount);
});
}
else {
if (tbodyElement.find("#HRbody" + f).find("#HRbody" + count + "_" + "HRTaxRateTypeId" + "_" + f).length > 0) {
tbodyElement.find("#HRbody" + f).find("#HRbody" + count + "_" + "HRTaxRateTypeId" + "_" + f).attr("id", "HRbody" + varCount + "_" + "HRTaxRateTypeId" + "_" + f);
var PreviouValues_TaxRateType = $("#HRbody" + count + "_" + "HRTaxRateTypeId" + "_" + f).val();
tbodyElement.find("#HRbody" + f).find("#HRbody" + varCount + "_" + "HRTaxRateTypeId" + "_" + f).val(PreviouValues_TaxRateType.toString());
tbodyElement.find("#HRbody" + f).find("#HRbody" + varCount + "_" + "HRTaxRateTypeId" + "_" + f).unbind('change');
tbodyElement.find("#HRbody" + f).find("#HRbody" + varCount + "_" + "HRTaxRateTypeId" + "_" + f).change(function () {
Calculate_Total_TaxAmount("HRbody" + varCount);
});
}
}
//TaxAmount
if (tbodyElement.find("#HRbody" + f).find("#HRbody" + count + "_" + "HRTaxRateAmount" + count).length > 0) {
tbodyElement.find("#HRbody" + f).find("#HRbody" + count + "_" + "HRTaxRateAmount" + count).attr("id", "HRbody" + varCount + "_" + "HRTaxRateAmount" + f);
var LastAmount = $(".BaseBody" + count).find("#tblTaxMainRM").find("#HRbody" + f).find("#HRbody" + count + "_" + "HRTaxRateAmount" + f).val();
tbodyElement.find("#HRbody" + f).find("#HRbody" + varCount + "_" + "HRTaxRateAmount" + f).val(LastAmount);
tbodyElement.find("#HRbody" + f).find("#HRbody" + varCount + "_" + "HRTaxRateAmount" + f).unbind('change');
tbodyElement.find("#HRbody" + f).find("#HRbody" + varCount + "_" + "HRTaxRateAmount" + f).change(function () {
Calculate_Total_TaxAmount("HRbody" + varCount);
});
}
else {
if (tbodyElement.find("#HRbody" + f).find("#HRbody" + count + "_" + "HRTaxRateAmount" + f).length > 0) {
tbodyElement.find("#HRbody" + f).find("#HRbody" + count + "_" + "HRTaxRateAmount" + f).attr("id", "HRbody" + varCount + "_" + "HRTaxRateAmount" + f);
var LastAmount = $(".BaseBody" + count).find("#tblTaxMainRM").find("#HRbody" + f).find("#HRbody" + count + "_" + "HRTaxRateAmount" + f).val();
tbodyElement.find("#HRbody" + f).find("#HRbody" + varCount + "_" + "HRTaxRateAmount" + f).val(LastAmount);
tbodyElement.find("#HRbody" + f).find("#HRbody" + varCount + "_" + "HRTaxRateAmount" + f).unbind('change');
tbodyElement.find("#HRbody" + f).find("#HRbody" + varCount + "_" + "HRTaxRateAmount" + f).change(function () {
Calculate_Total_TaxAmount("HRbody" + varCount);
});
}
}
//TaxRefundable.
if (tbodyElement.find("#HRbody" + f).find("#HRbody" + count + "_" + "HRTaxRefundable" + count).length > 0) {
tbodyElement.find("#HRbody" + f).find("#HRbody" + count + "_" + "HRTaxRefundable" + count).attr("id", "HRbody" + varCount + "_" + "HRTaxRefundable" + f);
tbodyElement.find("#HRbody" + f).find("#HRbody" + varCount + "_" + "HRTaxRefundable" + f).val($("#edithotelroomrate").find("#HRtblMain").find("#HRbody" + count).find("#tblTaxMainHR").find("#HRbody" + f).find("#HRbody" + count + "_" + "HRTaxRefundable" + f).val());
}
else {
if (tbodyElement.find("#HRbody" + f).find("#HRbody" + count + "_" + "HRTaxRefundable" + f).length > 0) {
tbodyElement.find("#HRbody" + f).find("#HRbody" + count + "_" + "HRTaxRefundable" + f).attr("id", "HRbody" + varCount + "_" + "HRTaxRefundable" + f);
tbodyElement.find("#HRbody" + f).find("#HRbody" + varCount + "_" + "HRTaxRefundable" + f).val($("#edithotelroomrate").find("#HRtblMain").find("#HRbody" + count).find("#tblTaxMainHR").find("#HRbody" + f).find("#HRbody" + count + "_" + "HRTaxRefundable" + f).val());
}
}
if (tbodyElement.find("#HRbody" + f).find("#DeleteTaxRecord" + f).length > 0) {
tbodyElement.find("#HRbody" + f).find("#DeleteTaxRecord" + f).remove();
tbodyElement.find("#HRbody" + f).find("#DeleteTaxRecords" + f).append("<input type='button' id=DeleteTaxRecord" + f + " value = 'Delete Tax Record' onClick='DeleteMultipalTaxEntry(" + f + "," + "HRbody" + varCount + ")' />");
}
else {
}
tbodyElement.find('#btnAddMultipaltax' + f).attr("id", "btnAddMultipaltax" + f);
tbodyElement.find("#btnAddMultipaltax" + f).attr('onclick', '').unbind('click');
tbodyElement.find("#btnAddMultipaltax" + f).unbind('click');
tbodyElement.find("#btnAddMultipaltax" + f).click(function (e) {
AddMultipalTax(0, "HRbody" + varCount);
});
}
$("#edithotelroomrate").find("#HRtblMain").find("#HRbody" + varCount).find("#ManipulationofService" + lstCount).attr('id', 'ManipulationofService' + varCount);
tbodyElement.find("#HRTripleRoomRate" + count).attr('id', 'HRTripleRoomRate' + varCount);
tbodyElement.find("#HRQuadRoomRate" + count).attr('id', 'HRQuadRoomRate' + varCount);
tbodyElement.find("#HRNoOfSingles" + count).attr('id', 'HRNoOfSingles' + varCount);
tbodyElement.find("#HRSpecialRoomRate" + count).attr('id', 'HRSpecialRoomRate' + varCount);
tbodyElement.find("#HREarlyCheckInSngRate" + count).attr('id', 'HREarlyCheckInSngRate' + varCount);
tbodyElement.find("#HRLateCheckOutSngRate" + count).attr('id', 'HRLateCheckOutSngRate' + varCount);
tbodyElement.find("#HREarlyCheckInDblRate" + count).attr('id', 'HREarlyCheckInDblRate' + varCount);
tbodyElement.find("#HRLateCheckOutDblRate" + count).attr('id', 'HRLateCheckOutDblRate' + varCount);
$("#HRisNEW" + varCount).val("NEW");
if (tbodyElement.find("#HRTaxIncludedInRate" + count).is(":checked")) {
isChecked = true;
$("#HRisIncludedInRate" + varCount).val("true");
} else {
isChecked = false;
$("#HRisIncludedInRate" + varCount).val("false");
}
if ($("#HRTaxRefundable" + varCount).is(":checked")) {
$("#HRisTaxRefundable" + varCount).val("true");
} else {
$("#HRisTaxRefundable" + varCount).val("false");
}
$("#HRSingleRoomRate" + count).removeAttr("value");
$("#HRDoubleRoomRate" + lstCount).removeAttr("value");
$("#HRTripleRoomRate" + lstCount).removeAttr("value");
$("#HRQuadRoomRate" + lstCount).removeAttr("value");
$("#HRSinglesathalfdbl" + lstCount).removeAttr("value");
$("#HRNoOfSingles" + lstCount).removeAttr("value");
$("#HRSpecialRoomRate" + lstCount).removeAttr("value");
$("#HREarlyCheckInSngRate" + lstCount).removeAttr("value");
$("#HRLateCheckOutSngRate" + lstCount).removeAttr("value");
$("#HREarlyCheckInDblRate" + lstCount).removeAttr("value");
$("#HRLateCheckOutDblRate" + lstCount).removeAttr("value");
//$("#HRTaxRateAmount" + lstCount).removeAttr("value");
$("#HRSingleRoomRate" + lstCount).attr("value", $("#HRSingleRoomRate" + varCount).val());
$("#HRDoubleRoomRate" + lstCount).attr("value", $("#HRDoubleRoomRate" + varCount).val());
$("#HRTripleRoomRate" + lstCount).attr("value", $("#HRTripleRoomRate" + varCount).val());
$("#HRQuadRoomRate" + lstCount).attr("value", $("#HRQuadRoomRate" + varCount).val());
$("#HRSinglesathalfdbl" + lstCount).attr("value", $("#HRSinglesathalfdbl" + varCount).val());
$("#HRNoOfSingles" + lstCount).attr("value", $("#HRNoOfSingles" + varCount).val());
$("#HRSpecialRoomRate" + lstCount).attr("value", $("#HRSpecialRoomRate" + varCount).val());
$("#HREarlyCheckInSngRate" + lstCount).attr("value", $("#HREarlyCheckInSngRate" + varCount).val());
$("#HRLateCheckOutSngRate" + lstCount).attr("value", $("#HRLateCheckOutSngRate" + varCount).val());
$("#HREarlyCheckInDblRate" + lstCount).attr("value", $("#HREarlyCheckInDblRate" + varCount).val());
$("#HRLateCheckOutDblRate" + lstCount).attr("value", $("#HRLateCheckOutDblRate" + varCount).val());
//$("#HRTaxRateAmount" + lstCount).attr("value", $("#HRTaxRateAmount" + varCount).val());
$("#hrtaxratetypeid" + varCount).val($("#hrtaxratetypeid" + count).val());
$("#rateunit" + varCount).val($("#rateunit" + count).val());
$("#daytype" + varCount).val($("#daytype" + count).val());
$("#hrtaxtype" + varCount).val($("#hrtaxtype" + count).val());
$("#edithotelroomrate").find("#HRbody" + varCount).find("#HRremove" + lstCount).remove();
$("#edithotelroomrate").find("#HRbody" + varCount).find("#HRbtnDuplicate" + lstCount).remove();
if ($("#edithotelroomrate").find("#HRbody" + varCount).children("tr").eq(0).children("td").eq(1) != null) {
$("#edithotelroomrate").find("#HRbody" + varCount).children("tr").eq(0).children("td").eq(1).remove();
}
//Code for new button creation and assigning the required attributes for the same
$("#edithotelroomrate").find("#HRtblMain").find("#HRbody" + varCount).find("#ManipulationofService" + varCount).children("td:eq(0)").append("<input type='button' id='HRremove" + varCount + "' value='Remove this Service' onclick='RemoveSelectedServiceHR(" + varCount + "," + rateid + ");' />");
$("#edithotelroomrate").find("#HRtblMain").find("#HRbody" + varCount).find("#ManipulationofService" + varCount).children("td:eq(0)").append("<input type='button' id='HRbtnDuplicate" + varCount + "' value='Duplicate this Service' onclick='AddDuplicateHR(" + varCount + "," + rateid + "," + "HRbody" + varCount + ");' />");
var LenghtOfDupliLabel = tbodyElement.find("#ManipulationofService" + varCount).find("label").length;
if (LenghtOfDupliLabel == 0) {
$("#edithotelroomrate").find("#HRtblMain").find("#HRbody" + varCount).find("#ManipulationofService" + varCount).children("td:eq(0)").append("<td align='right' colspan='4'> <label style='font-size:0.8em;margin-right:25px; font-weight:bold; color:black;' for='#'>Duplicate</label></td>");
}
else {
$("#edithotelroomrate").find("#HRtblMain").find("#HRbody" + varCount).find("#ManipulationofService" + varCount).children("td").find("label").remove();
$("#edithotelroomrate").find("#HRtblMain").find("#HRbody" + varCount).find("#ManipulationofService" + varCount).children("td:eq(0)").append("<td align='right' colspan='4'> <label style='font-size:0.8em;margin-right:25px; font-weight:bold; color:black;' for='#'>Duplicate</label></td>");
}
$("#edithotelroomrate").find("#HRtblMain >tBody").each(function (index) {
var CurrentBodyName = $(this).attr("id");
$(this).find("input[id*=_HRTaxRateAmount]").attr('onchange', '').unbind('onchange');
$(this).find("#HRSingleRoomRate" + index).unbind('change');
$(this).find("#HRSingleRoomRate" + index).change(function () {
Calculate_Total_TaxAmount(CurrentBodyName);
});
});
alert("Service Duplicated Successfully.");
// //Code for duplicated element adding underneath the parent element
/* $().ready(function () {
$('#HRTaxIncludedInRate' + varCount).click(function () {
DisableHRAmountDuplicate(varCount);
if ($("#HRTaxIncludedInRate" + varCount).is(":checked")) {
$("#HRisIncludedInRate" + varCount).val("true");
}
else {
$("#HRisIncludedInRate" + varCount).val("false");
}
});
$('#HRTaxRefundable' + varCount).click(function () {
if ($("#HRTaxRefundable" + varCount).is(":checked")) {
$("#HRisTaxRefundable" + varCount).val("true");
}
else {
$("#HRisTaxRefundable" + varCount).val("false");
}
});
var j = 0;
var val = [];
for (var i = 0; i < varCount; i++) {
var id = $("#HRtblMain").find("tbody")[i].id;
if ($("#" + id).is(":empty")) {
continue;
} else {
var num = id.replace("HRbody", "");
val[j] = num;
j++;
}
}
var totCount = val.length;
//alert(totCount);
j = 1;
for (var i = 0; i <= varCount; i++) {
var id = $("#HRtblMain").find("tbody")[i].id;
if ($("#" + id).is(":empty")) {
continue;
}
else {
$("#" + id).children("tr").eq(23).empty();
$("#" + id).children("tr").eq(23).append("<td align='right' colspan='4'><label for='#'> " + (j) + " of " + (totCount + 1) + " </label></td>");
j++;
}
}
});*/
}
else {
return false;
}
}