Discussion Locked

Hard Q, Printing a hyperlink from a FORM

0 helpful
9 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

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.

[code]

[/code]

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

[code]

Response.write ""
[/code]

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

9 replies

by peyison

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 ""
-----------------

more to follow...

by peyison

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:
"
Reports= Split(Reports,",")
For I = 0 to UBound(Reports)
Response.Write Reports(I) & "
"
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.

by kanejone

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

by kanejone

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

by kanejone

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

by kanejone

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.

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........

by kanejone

document.body.insertAdjacentHTML("beforeEnd","");
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",
"");
doc = printHiddenFrame.document;
doc.open();
doc.write(
"" +
"" +
"");
doc.close();
}

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

by kanejone

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

<%@Language=VBScript%>

Really important make sure you also put the following in the body tag.
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

This discussion is closed to new replies.