Wednesday 28 August 2013

Javascript function to print the selected Div Tag content

Please find the javascript (no JQuery) function below to print the selected content below;
// To print selected portion of HTML content
function printDivContents(divId) {    
 var divToPrint = document.getElementById(divId);
 var popupWin = window.open('', '_blank', 'width=500,height=500,scrollbars=yes');
 popupWin.document.open();
 popupWin.document.write('< html>< body onload="window.print()">' + divToPrint.innerHTML + '');
 popupWin.document.close();
}

Thursday 22 August 2013

Reloading/Refreshing the image element(same filename) via Jquery AJAX

How to reload/refresh an element(image) in jQuery : Reloading/Refreshing the image element(same filename) via Jquery AJAX
$("#image1").attr("src", "{$base_url}tmp/survey/image1.png?ts=" + new Date().getTime());
$("#image2").attr("src", "{$base_url}tmp/survey/image2.png?ts=" + new Date().getTime());
Please check below the example of deployed function via AJAX...

function viewReportBtn(id) 
{  
 $('#survey_id').val(id);
 $('#dvLoading').show(); // Loader On
 
 var formData = $("#thisForm").serialize();
 
 $.ajax({ url: '{$base_url}school/reports/view',
  data: formData,
  type: 'post',
  complete: function(output) {
   var str = output.responseText;
   resultStatus = str.substr(0,7);
   resultText = str.substr(7,(str.length));
   
   if (resultStatus == 'success') {
    $('#searchResult').show().html(resultText); // show the result list on a search result container
    $("#lineChart").attr("src", "{$base_url}tmp/survey/linechart.png?ts=" + new Date().getTime());
    $("#pieChart").attr("src", "{$base_url}tmp/survey/piechart.png?ts=" + new Date().getTime());
   } else {
       $('#searchResult').html('').hide(); // hiding the search result container
   }
   $('#dvLoading').fadeOut(10); // To Switch Off the loader..
  }
 });
}