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?

Recommended Answers

All 8 Replies

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

Member Avatar for rajarajan2017
window.open

will open the new window

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

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

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?

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

i mailed you my code - please check

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";
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.