General discussion

Locked

Hard Q, Printing a hyperlink from a FORM

By kanejone ·
Hi Guys
I have a table that contains a form. The table has hyperlinks to other html pages with a input box (checkbox) beside. What I am trying to do, is have a button at the end of the form that will print all the hyperlinks that have been selected using the checkboxes. Here is the code that is generated by my ASP page.



<form name='form2'>
<table border = 0>
<tr>
<td bgcolor='#ffffcc'>
<a href = '#' onclick = window.open('http://100.100.100.100/Reports/REPORTS_20.htm','javascript_1','height=600,width=700,resizable,scrollbars=yes')>SUMMARY_REPORTS_20010220.htm</a><BR></td>
<td bgcolor = '#336699'>
<input type='checkbox' name = 'REPORTS_20.htm' style='HEIGHT: 22px; WIDTH: 99px'></td>
</tr>
<tr>
<td bgcolor='#ffffcc'>
<a href = '#' onclick = window.open('http://100.100.100.100/Reports/REPORTS_21.htm','javascript_1','height=600,width=700,resizable,scrollbars=yes')>CROSS_CURRENCY_REPORTS_20010220.htm</a><BR>
</td>
<td bgcolor = '#336699'><input type='checkbox' name = 'REPORTS_21.htm' style='HEIGHT: 22px; WIDTH: 99px'></td>
</tr>
</table>
</form>



Here is look at the ASP code that I use to generate this page




Response.write "<form name='form2'>"	 
Response.write "<table border= 0>"
Response.write ""
For Each objFile In objFSO.GetFolder("D:\Web Server\wwwroot\generatedReports\").Files 
Response.Write "<tr><td bgcolor='#ffffcc'><a href = '#' onclick = window.open('http://100.100.100.100/Reports/" & objFile.name & "','javascript_1','height=600,width=700,resizable,scrollbars=yes')>" & objFile.name &  "</a><BR></td>" 
Response.write "<td bgcolor = '#336699'><input type='checkbox' name = '" & objFile.name & "' style='HEIGHT: 22px; WIDTH: 99px'></td></tr>"
Next
Response.Write "</table>"
Response.Write "</form>"



I would really appreciate any help that anyone may be able to offer.
Cheers
JK

This conversation is currently closed to new comments.

9 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

Hard Q, Printing a hyperlink from a FORM

by Peyison In reply to Hard Q, Printing a hyperl ...

Since you can't really send text to a printer, following is a way that will send the text to a new page, that can then be printed from the browser.

The first thing is to make the name of the checkboxes the same, but make their values unique. In this example I set the value of each checkbox to the associated file name. If you want the entire link to be returned you can set the value to be the text of the link. I also added a method and action to the form tag. The form will post to a new page called reportlist.asp.

Here is the new code for the first page:

Response.write "<form name='form2' method='POST' action='reportlist.asp'>"
Response.write "<table border = 0>"
Response.write ""
For Each objFile In objFSO.GetFolder("D:\Web Server\wwwroot\generatedReports\").Files
Response.Write "<tr><td bgcolor='#ffffcc'><a href = '#' onclick = window.open('http://100.100.100.100/Reports/" & objFile.name & "','javascript_1','height=600,width=700,resizable,scrollbars =yes')>" & objFile.name & "</a><BR></td>"
Response.write "<td bgcolor = '#336699'><input type='checkbox' name='cbxReports' " & _
"value = '" & objFile.name & "' style='HEIGHT: 22px; WIDTH: 99px'></td></tr>"
Next
Response.write "<td bgcolor = '#336699'><input type='submit' value='Submit' name='cbtSubmit'>"
Response.Write "</table>"
Response.Write "</form>"
-----------------


more to follow...

Collapse -

Hard Q, Printing a hyperlink from a FORM

by Peyison In reply to Hard Q, Printing a hyperl ...

Here is the code for reportlist.asp:

Reports = Request.Form("cbxReports")
If Len(Reports)<1 Then
Response.Write "No reports selected."
Else
Response.Write "Selected Reports:<br>"
Reports= Split(Reports,",")
For I = 0 to UBound(Reports)
Response.Write Reports(I) & "<br>"
Next
End If
------------------

Since all of the textboxes have the same name, request.form("cbxReports") will return a comma delimited string of the values of the selected text boxes. The Split command converts the string to an array, using a comma to determine each new array element. The reports (or whatever text is in the values of the checkboxes) will be listed out. You can then print the page.

Hope this helps.

Collapse -

Hard Q, Printing a hyperlink from a FORM

by kanejone In reply to Hard Q, Printing a hyperl ...

Thanks for the help mate. I've found the answer and posted it as a commemt in my question. I've assigned you the points because you gave me an idea on how to solve another problem that I was working on.
All the best
JK

Collapse -

Hard Q, Printing a hyperlink from a FORM

by kanejone In reply to Hard Q, Printing a hyperl ...

Hi Peyison
Thanks for the help. I really appreciate it. unfortunately, I don't think that I was clear enough in describing what I was trying to do. What I am actually trying to do is print out the page behind the links in the table by selecting them using checkboxes.

For example I have a few links that I have in a form. Each link has a web page behind it and a checkbox associated with it. I want to be able to select the checkbox and then press the print button and whatever links have been selected I want the pages behind the links to be printed out.

Once again thanks for the help. I really appreciate your time.

Cheers JK

Collapse -

Hard Q, Printing a hyperlink from a FORM

by kanejone In reply to Hard Q, Printing a hyperl ...

I really need help with this topic and will assign points to everyone that helps me along the way. Thanks for the help guys.
JK

Collapse -

Hard Q, Printing a hyperlink from a FORM

by kanejone In reply to Hard Q, Printing a hyperl ...

Hi Peyison,
Thanks a lot for the help that you offered. I found the answer in the following code if anyone wants to have a look at it.
Included 2 .JS files that contained the following code.
<script defer language=JScript src="print.js"></script>
<script defer src="printHid.js"></script>

Print.JS contained:
// Priting with IE4/5 for AIB Cash Management Reports.


if ( printIsNativeSupport() )
window.print2 = window.print;
window.print = printFrame;

// main stuff
function printFrame(frame, onfinish) {
if ( !frame ) frame = window;

function execOnFinish() {
switch ( typeof(onfinish) ) {
case "string": execScript(onfinish); break;
case "function": onfinish();
}
if ( focused && !focused.disabled ) focused.focus();
}

if ( frame.document.readyState !== "complete" &&
!confirm("The document to print is not downloaded yet! Continue with printing?") )
{
execOnFinish();
return;
}

if ( window.print2 ) { // IE5
var focused = document.activeElement;
frame.focus();
if ( frame.print2 ) frame.print2();
else frame.print();
execOnFinish();
return;
}

var eventScope = printGetEventScope(frame);
var focused =document.activeElement;

window.printHelper = function() {
execScript("on error resume next: printWB.ExecWB 6, 1", "VBScript");
printFireEvent(frame, eventScope, "onafterprint");
printWB.outerHTML = "";
execOnFinish();
window.printHelper = null;
}

Continued on next comment........

Collapse -

Hard Q, Printing a hyperlink from a FORM

by kanejone In reply to Hard Q, Printing a hyperl ...

document.body.insertAdjacentHTML("beforeEnd","<object id=\"printWB\" width=0 height=0 \classid=\"clsid:8856F961-340A-11D0-A96B-00C04FD705A2\"></object>");
printFireEvent(frame, eventScope, "onbeforeprint");
frame.focus();
window.printHelper = printHelper;
setTimeout("window.printHelper()", 0);
}

// helpers
function printIsNativeSupport() {
var agent = window.navigator.userAgent;
var i = agent.indexOf("MSIE ")+5;
return parseInt(agent.substr(i)) >= 5 && agent.indexOf("5.0b1") < 0;
}

function printFireEvent(frame, obj, name) {
var handler = obj[name];
switch ( typeof(handler) ) {
case "string": frame.execScript(handler); break;
case "function": handler();
}
}

function printGetEventScope(frame) {
var frameset = frame.document.all.tags("FRAMESET");
if ( frameset.length ) return frameset[0];
return frame.document.body;
}


next file contained.....

Printhid.js
function printHidden(url)
{
document.body.insertAdjacentHTML("beforeEnd",
"<iframe name=printHiddenFrame width=0 height=0></iframe>");
doc = printHiddenFrame.document;
doc.open();
doc.write(
"<frameset onload='parent.onprintHiddenFrame()' rows=\"100%\">" +
"<frame name=printMe src=" +url+ ">" +
"</frameset>");
doc.close();
}

function onprintHiddenFrame() {
function onfinish() {
printHiddenFrame.outerHTML = "";
if ( window.onprintcomplete ) window.onprintcomplete();
}
printFrame(printHiddenFrame.printMe, onfinish);
}

Collapse -

Hard Q, Printing a hyperlink from a FORM

by kanejone In reply to Hard Q, Printing a hyperl ...

Finally I looped through the files in a particular directory by doing the following:

<%@Language=VBScript%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<script defer language=JScript src="print.js"></script>
<script defer src="printHid.js"></script>
<SCRIPT LANGUAGE="JavaScript">
function printURL()
{
window.onprintcomplete = function()
{
// window.navigate("../admin/a_print.asp");
}
<%
dim objFile_Print
dim objFSO_Print
dim valueDate_Print
valueDate_Print = Request.form("reValueDate")

Set objFSO_Print = Server.CreateObject("Scripting.FileSystemObject")
For Each objFile_Print In objFSO_Print.GetFolder("D:\Web Server\wwwroot\generatedReports\"& valueDate_Print & "\").Files
If Request.form(objFile_Print.name) = "on" Then
Response.Write "printHidden('http://100.100.100.100/generatedReports/" & valueDate_Print & "/" & objFile_Print.name & "');"
End If
Next


%>
}

function loadme()
{
printURL();
}
</SCRIPT>


Really important make sure you also put the following in the body tag.
<body onload="loadme()"> of the page.

Hope this helps someone. If anyone wants help or just wants me to send them the files just send me a mail.

Regards
JK

Collapse -

Hard Q, Printing a hyperlink from a FORM

by kanejone In reply to Hard Q, Printing a hyperl ...

This question was closed by the author

Back to Web Development Forum
9 total posts (Page 1 of 1)  

Related Discussions

Related Forums