I have a div
that contains some input
fields whose values are provided with jQuery.
Also I copied some code I found to print them, but when I press the button to print, the values from the fields are empty.
Here is my code:
<script>
$(document).ready(function() {
$('#name').val("Bruce");
$('#lastname').val("Lee");
$('#age').val("35");
});
</script>
<script>
$(document).ready(function() {
$("#printhem").click(function(){
var divContents = $("#printedDiv").html();
var printWindow = window.open('', '', 'height=700,width=900');
printWindow.document.write('<html><head><title>PRINTED</title>');
printWindow.document.write('</head><body >');
printWindow.document.write(divContents);
printWindow.document.write('</body></html>');
printWindow.document.close();
printWindow.print();
});
});
</script>
<div id="printedDiv"
<input name="name" type="text" id="name">
<input name="lastname" type="text" id="lastname">
<input name="age" type="text" id="age">
<div id="printhem">Print</div>
</div>