0

my code has a print button and when that is clicked i want a new window to open up wit a list of details that the user edits. that is all the data of the form. (only the values)
how do i do this?

4
Contributors
8
Replies
15
Views
7 Years
Discussion Span
Last Post by dean8710
0

In the opened popup window you can read the values of the parent window like,

window.opener.formname.elemname.value;

and then display this value on the pop up page

0

so what do u mean i shud write a function in js is it?
if so can u give me an example?

this is all i have done so far

<script type="text/javascript">

function Clickheretoprint()
{ 
  var disp_setting="toolbar=yes,location=no,directories=yes,menubar=yes,"; 
  disp_setting+="scrollbars=yes,width=650, height=600, left=100, top=25"; 
  var content_vlue = document.getElementById("formData").innerHTML; 
  
  var docprint=window.open("","",disp_setting); 
   docprint.document.open(); 
   docprint.document.write('<html><head><title>Print Results</title>'); 
   docprint.document.write('</head><body  onLoad="self.print()"><center>');          
   docprint.document.write(content_vlue);          
   docprint.document.write('</center></body></html>'); 
   docprint.document.close(); 
   docprint.focus(); 

}
function dataprint()
{ 
  var disp_setting="toolbar=yes,location=no,directories=yes,menubar=yes,"; 
  disp_setting+="scrollbars=yes,width=650, height=600, left=100, top=25"; 

  window.opener.formname.elemname.value;
}
</script>
</head>

<?php
0

Your Clickheretoprint() function is doing most of the part except reading the form values.
Since you are using document.write to render data in the popup window there is no need for prefixing window.opener to access the form elements. You can directly access them by
document.formname.elementname.value


Here is an example using the same function which reads the value in a textbox and displays it in the popup window.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
 <head>
  <title> New Document </title>
  <meta name="Generator" content="EditPlus">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
  <script type="text/javascript">
 
function Clickheretoprint()
{ 
  var disp_setting="toolbar=yes,location=no,directories=yes,menubar=yes,"; 
  disp_setting+="scrollbars=yes,width=650, height=600, left=100, top=25"; 
  //Reading the form elements value
  var content_vlue = document.myform.yourname.value; 
 
  var docprint=window.open("","",disp_setting); 
   docprint.document.open(); 
   docprint.document.write('<html><head><title>Print Results</title>'); 
   docprint.document.write('</head><body  onLoad="self.print()"><center>');          
   docprint.document.write(content_vlue);          
   docprint.document.write('</center></body></html>'); 
   docprint.document.close(); 
   docprint.focus(); 
 
}

</script>
 </head>

 <body>
 <form name="myform" method=post action="">
	<input type="text" name="yourname" value="">
	<input type="button" value="Test" onclick="Clickheretoprint()">
 </form>  
 </body>
</html>

Hope this helps

0

ok so u mean instead of this line var content_vlue = document.getElementById("formData").innerHTML; i should use
var content_vlue = document.myform.yourname.value; is it??
but then i wont need that div called formData either right?
i can just use that like u said var content_vlue = document.myform.yourname.value; continuously for all the values i want outputted right?

0

Yeah you are right. From what I understand about the flow in the code sample you posted, using code similar to
document.myform.yourname.value
for other form elements should be sufficient to read the values

Edited by parry_kulk: n/a

0

How to hide the popup box, so user can directly view the print page behind?

because if we close the pop up box, the printing view also disappeared.
please

var disp_setting="toolbar=yes,location=no,directories=yes,menubar=yes,"; 
  disp_setting+="scrollbars=yes,width=650, height=600, left=100, top=25";
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.