title: Changing Similar Code Into One for All Files
body: <p>I have about 30 different modules for my CMS and the following is code is included on every module's javascript except for a just a few changes and didn't know if there is an easier way or something more I can do to eliminate having to copy the same code over and over just in case I have to go back and change something I can only do it once. But the parts that are different on the pages is anything that says the word templates is different on each page because it represents the modular name. I didn't know if I could change stuff to be like itemID and whatever else.</p>
  
  <pre><code>$('.ask').jConfirmAction( {
      question : "Are you sure you want to delete the selected row?", 
      yesAnswer : "Yes", 
      cancelAnswer : "No", 
      onYes: function(evt) { 
        templates(evt.target); 
      }
  });
  
  $('.ask2').jConfirmAction( {
      question : "Are you sure you want to delete all selected rows?",
      questionClass: "question2", 
      onYes: function(evt){
          templatesArray(evt.target); 
      }
  });
  
  function templates(whatsThis) {
      var templateID = $(whatsThis).parents('td').find('img').attr('id');
      var dataString = 'templateID=' + templateID + '&amp;deleteTemplate=True'; 
  
      var iRow = oTable.fnGetPosition( $(whatsThis).parents('tr').get(0));
  
      $.ajax({ 
          type: "POST", 
          url: "processes/templates.php", 
          data: dataString,
          success: function(data) {
              if (data.errorsExist) {
              } else {
                  oTable.fnDeleteRow(iRow);     // remove the row from the table
                  if(oTable.fnSettings().fnRecordsTotal() == 0) {
                      $('.bt_red').remove();
                      $('.bt_blue').remove();
                  }
                  if(oTable.fnSettings().fnRecordsTotal() &lt;= 10) {
                      $('.bt_blue').remove();
                  }
              } 
          }
      });
  }
  
  
  function templatesArray(whatsThis) {
      var myNewArray = new Array(); 
      var aRow = new Array();
  
      $('input:checkbox[name="templates"]:checked').each(function(i) { 
          myNewArray.push($(this).val());
          aRow.push($(this).closest('tr')[0]);
      }); 
      var dataString = 'templatesArray=' + myNewArray + '&amp;deleteTemplatesArray=True'; 
      $.ajax({ 
          type: "POST", 
          url: "processes/templates.php", 
          data: dataString,
          success: function(data) {
              if (data.errorsExist) {
              } else {
                  $(whatsThis).parents("tr").eq(0).hide(); 
                  for (i in aRow)  // loop over the array of row indexes
                    oTable.fnDeleteRow(aRow[i]);
                  if(oTable.fnSettings().fnRecordsTotal() == 0) {
                      $('.bt_red').remove();
                      $('.bt_blue').remove();
                  }
                  if(oTable.fnSettings().fnRecordsTotal() &lt;= 10) {
                      $('.bt_blue').remove();
                  }                      
              } 
          }
      });
  
  }
  </code></pre>