Solved

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

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This article discusses how to create an extensible mechanism for linked drop downs.
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
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 …

733 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