Solved

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

Posted on 2011-03-14
4
549 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…

770 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