var addOptionTextRow = {};
var removeOptionTextRow = {};
$(function() {
    var updateName = function(name, index) {
        var sub = name.substring(0, name.length - 1);
        return sub + index;
    };
    var clearContent = function(row) {
        for (var index = 0; index < row.childNodes.length; index++) {
            var cell = row.childNodes[index];
            var element = cell.childNodes[0];
            var name = $(element).attr('name');
            if (name) {
                $(cell.childNodes[0]).val('');
            }
        }
    };
    var generateId = function(root, row) {
        var rowCount = $(root).data('rowCount');
        if (!rowCount) {
            rowCount = 1;
            $(root).data('rowCount', rowCount);
        } else {
            rowCount++;
            $(root).data('rowCount', rowCount);
        }
        for (var index = 0; index < row.childNodes.length; index++) {
            var cell = row.childNodes[index];
            var element = cell.childNodes[0];
            var name = $(element).attr('name');
            if (name) {
                $(element).attr('name', updateName(name, rowCount));
            }
        }
    };
    var countRows = function(root) {
        var count = root.childNodes.length;
        return count;
    };
    addOptionTextRow = function(el) {
        var root = el.parentNode.parentNode.parentNode;
        //Check if there is a saved template in the root
        var template = $(root).data('template');
        if (template) {
            generateId(root, template);
            var clone = $(template).clone();
        } else {
            var row = root.childNodes[2];
            generateId(root, row);
            var clone = $(row).clone();
        }
        clearContent(clone[0]);
        clone.appendTo(root);
    };
    removeOptionTextRow = function(el) {
        var row = el.parentNode.parentNode;
        var root = row.parentNode;
        var rowCount = $(root).data('rowCount');
        if (!rowCount) {
            rowCount = countRows(root);
            $(root).data('rowCount', rowCount);
        }
        $(root).data('template', row);
        //Cache this row before removal
        $(row).remove();
    };
});
@@ -1,245 +1,1283 @@
-var addOptionTextRow = %7B%7D;%0Avar removeOptionTextRow = %7B%7D;%0A$(function() %7B%0A    var updateName = function(name, index) %7B%0A        var sub = name.substring(0, name.length - 1);%0A        return sub + index;%0A    %7D;%0A    var clearContent = function(row
+/**%0A * The script is used to handle the rendering of the options text field type.It handles%0A * - Adding of new rows%0A * - Removal of existing rows;%0A * @type %7BObject%7D%0A */%0Avar addOptionTextRow = %7B%7D;%0Avar removeOptionTextRow = %7B%7D;%0A$(function() %7B%0A    var ROW_COUNT = 'rowCount'; //A counter which maintains the number of rows created in order to generate unique ids for each row%0A    var ROW_TEMPLATE = 'template';%0A    /**%0A     * The function generates a unique name given the current name of an element and an index%0A     * @param  %7B%5Btype%5D%7D name  The current name of the element%0A     * @param  %7B%5Btype%5D%7D index A unique index value%0A     * @return %7B%5Btype%5D%7D       A unique name based on the current name and the provided index.It can be considered unique for the lifetime of the page%0A     */%0A    var updateName = function(name, index) %7B%0A        var sub = name.substring(0, name.length - 1);%0A        return sub + index;%0A    %7D;%0A    /**%0A     * The function resets the contents of the row since the new rows%0A     * which are added contain the values of the template%0A     * @param  %7B%5Btype%5D%7D row %5Bdescription%5D%0A     */%0A    var clearContent = function(row) %7B%0A        iterateRow(row, function(cell) %7B%0A            $(cell.childNodes%5B0%5D).val('');%0A        %7D)%0A    %7D;%0A    var iterateRow = function(row, fn
 ) %7B%0A
@@ -1530,36 +1530,15 @@
     
-$
+fn
 (cell
-.childNodes%5B0%5D).val(''
 );%0A 
@@ -1642,34 +1642,33 @@
 (root).data(
-'rowCount'
+ROW_COUNT
 );%0A        i
@@ -1713,56 +1713,8 @@
  1;%0A
-            $(root).data('rowCount', rowCount);%0A
     
@@ -1750,24 +1750,30 @@
 ount++;%0A    
+    %7D%0A
         $(ro
@@ -1777,34 +1777,33 @@
 (root).data(
-'rowCount'
+ROW_COUNT
 , rowCount);
@@ -1815,125 +1815,40 @@
     
-%7D%0A        for (var index = 0; index %3C row.childNodes.length; index++) %7B%0A            var cell = row.childNodes%5Bindex%5D;
+iterateRow(row, function(cell) %7B
 %0A   
@@ -1942,36 +1942,8 @@
 ');%0A
-            if (name) %7B%0A    
     
@@ -2007,39 +2007,27 @@
 ));%0A        
-    %7D%0A        %7D
+%7D);
 %0A    %7D;%0A    
@@ -2319,26 +2319,28 @@
 t).data(
-'template'
+ROW_TEMPLATE
 );%0A     
@@ -2812,26 +2812,25 @@
 t).data(
-'rowCount'
+ROW_COUNT
 );%0A     
@@ -2914,26 +2914,25 @@
 t).data(
-'rowCount'
+ROW_COUNT
 , rowCou
@@ -2958,78 +2958,80 @@
     
-$(root).data('template', row);%0A        //Cache this row before removal
+//Cache this row before removal%0A        $(root).data(ROW_TEMPLATE, row);
 %0A   

Refactored the option text code to remove duplication