?
Solved

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

Posted on 2011-03-14
4
Medium Priority
?
554 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

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

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

752 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