Solved

How to use <input type="image.. to popup window

Posted on 2011-03-14
4
548 Views
Last Modified: 2012-05-11
I'm using the following form code to generate a 'print' page. I would like to have the new window pop-up then open the print dialog window. How would I do this?
<div style="margin-right: 50px; padding-top: 8.1em; text-align: right;">
	<form action="<?php echo $arch_config['portfolio_url'] . "print_html.php" ?>" method="GET" name="hidden_form">
		<input type="hidden" name="order" id="hidden_order" value='Alphabetical' />
		<input type="hidden" name="filters[state]" id="hidden_state" value="" />
		<input type="hidden" name="filters[county]" id="hidden_county" value="" />
		<input type="hidden" name="filters[city]" id="hidden_city" value="" />
		<input type="hidden" name="filters[denomination]" id="hidden_denomination" value="" />
		<input type="hidden" name="filters[service]" id="hidden_service" value="" />
		<input type="hidden" name="filters[has_images]" id=hidden_has_images value="" />
		<input type="image" src="images/print_image.jpg" />
	</form>
</div>

Open in new window

0
Comment
Question by:dnotestine
  • 2
  • 2
4 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 35133780
For example :

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script language="javascript">
	function printit() {
		//var hidden_form = document.getElementById("hidden_form");
		var hidden_form = document.getElementsByName("hidden_form")[0];
		var inputs = hidden_form.getElementsByTagName("input");
		var params = "?";
		for(var i=0;i<inputs.length;i++) {
			if( inputs[i].type == "hidden" && inputs[i].name.length!=0 && true) { // last true ready to put a new condition :)
				var name = inputs[i].name;
				var value = inputs[i].value;
				params += (i>0)?("&" + name + "=" + encodeURIComponent(value)):(name + "=" + encodeURIComponent(value))
			}
		}
		alert(params);
		w = window.open( hidden_form.action + params );
		return false;
	}
</script>
</head>
<body>
<div style="margin-right: 50px; padding-top: 8.1em; text-align: right;">
	<form action="<?php echo $arch_config['odesign/portfolio_url'] . "print_html.php" ?>" method="GET" name="hidden_form">
		<input type="hidden" name="order" id="hidden_order" value='Alphabetical' />
		<input type="hidden" name="filters[state]" id="hidden_state" value="" />
		<input type="hidden" name="filters[county]" id="hidden_county" value="" />
		<input type="hidden" name="filters[city]" id="hidden_city" value="" />
		<input type="hidden" name="filters[denomination]" id="hidden_denomination" value="" />
		<input type="hidden" name="filters[service]" id="hidden_service" value="" />
		<input type="hidden" name="filters[has_images]" id="hidden_has_images" value="" />
		<input type="image" src="http://technabob.com/blog/wp-content/uploads/2009/06/hp-web-printer-1.jpg" onclick="return printit();" />
	</form>
</div>
</body>
</html>

Open in new window

0
 

Author Comment

by:dnotestine
ID: 35133851
That opens a new window once I took the alert out :-) but how about the print dialog opening?
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 35133895
good, check this :

		w.onload = function() {
			this.print();
		}

Open in new window


Full page :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script language="javascript">
	function printit() {
		//var hidden_form = document.getElementById("hidden_form");
		var hidden_form = document.getElementsByName("hidden_form")[0];
		var inputs = hidden_form.getElementsByTagName("input");
		var params = "?";
		for(var i=0;i<inputs.length;i++) {
			if( inputs[i].type == "hidden" && inputs[i].name.length!=0 && true) { // last true ready to put a new condition :)
				var name = inputs[i].name;
				var value = inputs[i].value;
				params += (i>0)?("&" + name + "=" + encodeURIComponent(value)):(name + "=" + encodeURIComponent(value))
			}
		}
		//alert(params);
		w = window.open( hidden_form.action + params );
		w.onload = function() {
			this.print();
		}
		return false;
	}
</script>
</head>
<body>
<div style="margin-right: 50px; padding-top: 8.1em; text-align: right;">
	<form action="<?php echo $arch_config['odesign/portfolio_url'] . "print_html.php" ?>" method="GET" name="hidden_form">
		<input type="hidden" name="order" id="hidden_order" value='Alphabetical' />
		<input type="hidden" name="filters[state]" id="hidden_state" value="" />
		<input type="hidden" name="filters[county]" id="hidden_county" value="" />
		<input type="hidden" name="filters[city]" id="hidden_city" value="" />
		<input type="hidden" name="filters[denomination]" id="hidden_denomination" value="" />
		<input type="hidden" name="filters[service]" id="hidden_service" value="" />
		<input type="hidden" name="filters[has_images]" id="hidden_has_images" value="" />
		<input type="image" src="http://technabob.com/blog/wp-content/uploads/2009/06/hp-web-printer-1.jpg" onclick="return printit();" />
	</form>
</div>
</body>
</html>

Open in new window

0
 

Author Comment

by:dnotestine
ID: 35133937
I got it
<body onload="window.print();">

Thank you very much
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses how to create an extensible mechanism for linked drop downs.
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now