We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,494 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Printing values entered to a edit form

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
1 Year
Discussion Span
1 Year Ago
Last Updated
9
Views
rukshilag
Junior Poster
101 posts since Oct 2009
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 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

parry_kulk
Junior Poster
Team Colleague
167 posts since Jan 2007
Reputation Points: 26
Solved Threads: 41
Skill Endorsements: 0
window.open

will open the new window

rajarajan07
Nearly a Posting Virtuoso
1,450 posts since May 2008
Reputation Points: 167
Solved Threads: 241
Skill Endorsements: 1

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
rukshilag
Junior Poster
101 posts since Oct 2009
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 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

parry_kulk
Junior Poster
Team Colleague
167 posts since Jan 2007
Reputation Points: 26
Solved Threads: 41
Skill Endorsements: 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?

rukshilag
Junior Poster
101 posts since Oct 2009
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 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

parry_kulk
Junior Poster
Team Colleague
167 posts since Jan 2007
Reputation Points: 26
Solved Threads: 41
Skill Endorsements: 0

i mailed you my code - please check

rukshilag
Junior Poster
101 posts since Oct 2009
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 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";
dean8710
Junior Poster in Training
66 posts since Jul 2011
Reputation Points: 7
Solved Threads: 3
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.1028 seconds using 2.69MB