Solved

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

Posted on 2011-03-14
4
547 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
I got it
<body onload="window.print();">

Thank you very much
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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…
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

763 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

13 Experts available now in Live!

Get 1:1 Help Now