Click here to Skip to main content
15,885,875 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear friends,

I am trying to print the divs content with the help of jquery.
But its not printing the latest changes done to the HTML elements its only printing the values and html elements those are initially returned by server side php via ajax and jason.

In other words I am dynamically populating the reservediv at first, then I apply other jquery script to update those dynamically created html elements values and I can see my results on screen, but when I call the print function to take a print its printing only the old values inititally returned by the server not the new values on the screen


I would appreciate the help.

Many thanks in advance.



the code is as follows.

HTML
<div id="reservediv" class="divmargin" style="display: none;">


<input type="submit" value="Update" id="reserveupdate" style="display: none;" />
<input type="button" value="Print" onclick="PrintElem('#reservediv')" class="btnprnt"  />
<input type="button" value="Save" class="btnprnt" id="savereserve"/>
<div id="resultsaving" > </div>
<div id="reserveaccountbtn"style="display: none;">
<input type="submit" value="RESERVE-XXXXXX8751"  class="bankmovementsbtn" id="btnreserve" style="display: none;">
<input type="text" value="" id="reserveaccounttext" class="bankmovementsbtn"style="display: none;">

<div id="openingbaldiv" class="divopening">
<input type ="button" value="Beginning   Balance" class="reconfields" id="openingbalbutton"/>
<input type="text" value="0" class="reconfields" id="openingbaltext" >
</div>
<div id="reconcilediv" class="divreconcile">
<input type ="button" value="Ending  Balance" class="reconfields" id="closingbalbutton"/>
<input type="text" value="" id="closingbaltext"  class="reconfields">
</div>

<div id="clearedbaldiv" class="divclearedbal">
<input type ="button" value="Cleared   Balance" class="reconfields" id="clearedbalbutton"/>
<input type="text" value="" id="clearedbaltext" class="reconfields" >
</div>

<div id="differencebaldiv" class="divdifferencebal">
<input type ="button" value="Difference" class="reconfields" id="differencebalbutton"/>
<input type="text" value="" id="differencebaltext"  class="reconfields">
</div>

<input type ="button" value="Check All" id ="selectchbx" class = "update" /> 
<input type ="button" value="Uncheck  All" id ="selectunchbx" class = "update" /> 
<input type ="button" value="Calculate" id ="reconcilereserve" class = "update" /> 


Code to make print via jquery

JavaScript
<script type="text/javascript">
<!--
    function PrintElem(elem)
    {
        Popup($(elem).html());
    }

    function Popup(data) 
    {
        var mywindow = window.open('','Print Area','height=900 width=950');
		mywindow.document.write('<input type="text" id="messageprint1" value=" For  Firefox browser Press ctr+p to Print then close the Popup window, For Google Chrome just Press ctr+p to print" />');
        mywindow.document.write('<html><head><link REL="STYLESHEET" TYPE="text/css"  HREF="printout.css" media="print"> <link REL="STYLESHEET" TYPE="text/css" HREF="generatereports.css" media="screen">  <title>Print Area</title>');
        /*optional stylesheet*/ //mywindow.document.write('<link rel="stylesheet" href="main.css" type="text/css" />');
        mywindow.document.write('</head><body >');
        mywindow.document.write(data);
        mywindow.document.write('</body></html>');

        //mywindow.print();
        //mywindow.close();

        return true;
    } 
	
	</script>
Posted
Updated 17-Jan-13 15:26pm
v2

1 solution

This is working for me now



$(document).ready(function(){

$('div input').each(function(){
$(this).bind("change keyup input",function(){
$(this).attr('value',$(this).val());
});


});



$('div input:checkbox').each(function(){
$(this).bind('click', function() {
$(this).attr('checked',$(this).attr('checked'));
});


});



});
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900