Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

get db info and make new printer friendly window 1

Status
Not open for further replies.

kevpho

Programmer
Jun 9, 2003
47
CA
Hi All,

I haven't been able to find anything on the net to teach you how to do this, nor can I figure it out myself. What I have right now is a table of records from an Access database. Beside each record is a small "Print" link. When a user presses that "Print" link, I want a new window to open with all the information for that record displayed in a printer friendly version. A querystring selects the correct record for printing.

I haven't been able to figure out how to pass the database information into the new window. What I've tried is creating a form that posts to the new window with hidden fields, each one of these fields taking the value of the recordset. After the form I put a script that opens up a new window with "request.form" values ... but it won't read them properly. Not even sure if this is possible ..

If anyone has ideas on how to do this please respond. Thanks in advance.

Kevin
 
here we go
first thing is the query. I imagine you ahve this already seeing as the records are there. [wink]

so say it's a address book
name number
onpnt (222) 222-1111

this is printed to the screen with your initial query as
rs("name") rs("number")
(aside any formatting tables etc..)

what you can do is
Response.Write rs("name") & rs("number")
Response.Write &quot;<a href='printer.asp?name=&quot; & rs(&quot;name&quot;) & &quot;&number=&quot; & rs(&quot;number&quot;) & &quot; >[ print ]</a>&quot;

this should output
onpnt (222) 222-1111 [ print ]

[ print ] being a link (give or take some quotes there :))

in the page printer.asp just do
<html>
<%
Dim myName : myName = Request.QueryString(&quot;name&quot;)
Dim myNumber : myNumber = Request.QueryString(&quot;number&quot;)
Response.Write &quot;Values passed to page are <br>&quot;
Response.Write myName & myNumber
%>

what you did was pass the values accodingly to the increment written in your loop through the recordset as querystrings
you did this in the link with the ? and segragation of & between values.

if you are using a popup instead of a link to a actual page then you just concatinate these values by passing them to the client script in the event call as
onClick='popup(&quot;<%=rs(&quot;name&quot;)%>&quot;,&quot;<%=rs(&quot;number&quot;)%>&quot;)'

then concatinate with the javascript function written as this for a example
function popup(myName,myNumber) {
var url = printer.asp?name&quot; + myName + &quot;&number=&quot; + myNumber

then place the url in the path in the window.open




____________________________________________________
Python????? The other programming language you never thought of!
thread333-584700

onpnt2.gif
 
The querystring works great ... the only concern I have is that if I have a large number of fields I need to pass (some of which may include several sentences worth of data), the url becomes a very long string .. I'm not too sure if that poses a problem or not ?

and for the popup function, am i going to complete the function like this? (just to be clear)

function popup(myName,myNumber)
{
var url = &quot;printer.asp?name&quot; + myName + &quot;&number=&quot; + myNumber
window.open url
}

that way, when you click the &quot;print&quot; button on the side it calls the function and opens up a new window?

... well my day is done it's time to get off work ... thanks for your help onpnt ... will check back tomorrow

Kevin
 
For some reason the popup window isn't working properly for the printer friendly page. Here is the code:
Code:
<script language=&quot;Javascript&quot;>
  <!--
  function popUp(rNumber)
  {
    var url=&quot;printerfriendly.asp?RoomNumber&quot; + roomNumber;
    window.open url;
  }
  -->
</script>

and when I call it from within the asp page:
Code:
<a onClick=&quot;popUp('<%=rsInfo(&quot;RoomNumber&quot;)%>')&quot;> 
Print
</a>

Not sure if this is right or not ... and is it ok to have querystrings that may contain sentences? Thanks.

Kevin


 
Hey there,
the querystring length can be a issue. if it is then you may need to reqork things to the post method. at that point you will need to dynamicaly set the value to hidden fields and submit to a popup.

for what you have rate now though,
the big problem I see in the syntax is this line
var url=&quot;printerfriendly.asp?RoomNumber&quot; + roomNumber;

you need a &quot;=&quot; in there
var url=&quot;printerfriendly.asp?RoomNumber=&quot; + roomNumber;

the querystring request will not work if that is not there.
also have you tested the rs by Response.Write it out to debug a valid value? I know you probably have as you write them to the page but just want to double check.


____________________________________________________
Python????? The other programming language you never thought of!
thread333-584700

onpnt2.gif
 
O
also, you're not calling the aurgument your setting in the javascript function
function popUp(rNumber)

but you state + roomNumber;
it nees to be
+ rNumber;

just incase that wasn't a typo

____________________________________________________
Python????? The other programming language you never thought of!
thread333-584700

onpnt2.gif
 
Hi onpnt,

I have tested the value using the querystring earlier and it worked fine ... i'm getting an &quot;object expected&quot; error from the webpage, even after putting in the equals sign. For some reason, the &quot;Print&quot; text isn't even highlighting up as a link, but if I click on it I get an error. The error is on this line when I view the source (102 is the room number).
Code:
<a onClick=&quot;popUp('102')&quot;>Print</a>
Is there any where around that will teach me how to do what you propose, as in dynamically setting the value to hidden fields and submitting to the popup? I did try doing it but I think I did it entirely wrong .. at least my logic was wrong anyhow.

Thanks for your help

Kevin
 
hehe oops ya ... i've got typos all over the place ... same error though .. and I'm getting an &quot;expected ';'&quot; error when I load the page on line 16 ... but up to line 16 this is all i have (actual line 16 in red):
Code:
<%@ LANGUAGE=&quot;VBScript&quot; %>
<% Option Explicit %>
<!--#include file=&quot;../Include/logincheck.asp&quot;-->
<html>
<head>
<title>Print Work Orders</title>
  <script language=&quot;Javascript&quot;>
  <!--
function popUp(rNumber)
Code:
	{
	  var url = &quot;printerfriendly.asp?RoomNumber=&quot; + rNumber;
	  window.open url;
	}
  -->
  </script>

</head>
 
<a href=&quot;javascript:void(0);&quot; onClick=&quot;popUp('102')&quot;>Print</a>

The expected ; error is on the windoe.open
nees to be window.open(url);
I'll post a solution to the hidden fields in a bit as well. working on a tutorial to actually do the same thing.



____________________________________________________
Python????? The other programming language you never thought of!
thread333-584700

onpnt2.gif
 
Thanks for all your help ... works fine for the querystrings at least ... should've checked out the Javascript syntax on DevGuru or something ... ahh .. lots to learn ....
 
alrite i've had a bit of a move with the querystring thing, but now I'd like to post information from a hidden form to a new page. I have gotten it to work, but for some reason this javascript function won't submit properly. It works if I use submit buttons in the form, but I'd like to have a link that says &quot;Print&quot; instead of a big button. I'm pretty sure I have the correct syntax, but it says that

'document.formName' is null or not an object
Here's the code for the function:
Code:
<script language=&quot;Javascript&quot;>
<!--
  function submitForm(IDValue)
  {
    var formName = &quot;printInfo&quot; + IDValue;
    window.alert (formName);
    document.formName.submit();
  }
//-->
</script>

and for each record I make a separate form (kind of inefficient I know) ... there's a loop that generates it for each record ...
Code:
<form name=&quot;printInfo<%=rsInfo(&quot;WOID&quot;)%>&quot; method=&quot;POST&quot; action=&quot;woprinterfriendly.asp&quot;>
<input type=&quot;HIDDEN&quot; value=&quot;<%=rsInfo(&quot;Location&quot;)%>&quot; name=&quot;Location&quot;>
</form>
<a style=&quot;color:black&quot; href=&quot;javascript:void(0);&quot; onClick=&quot;submitForm(<%=rsInfo(&quot;WOID&quot;)%>)&quot;>Print</a>
(I put in the window.alert in the javascript function to check if a value comes out .. it does pass through correctly)

Can anyone spot my error? I haven't been able to find it ... thanks !!

Kevin

 
is there a submit button on the page anywhere that has a name attribute
eg:
<input type=&quot;submit&quot; name=&quot;submit&quot;>

if so take the name out. Also are you sure you're not getting multiple forms with the same name. That would also cause the error. It looks as though that's how your doing things. multiple form tags that is

you can also try the eval()
eval(&quot;document.&quot;+formName+&quot;.submit()&quot;);

the vairable enclosure may be the root cause. It sometimes will be excepted but other times not

____________________________________________________
Python????? The other programming language you never thought of!
thread333-584700

onpnt2.gif
 
umm there isn't any submit button on the page, and i've clicked on all the records to check the form names ... it works properly ... saying &quot;printInfo34&quot; or &quot;printInfo23&quot; so i'm pretty sure that should be ok ...

i tried replacing the &quot;document.formName.submit();&quot; line with

eval(&quot;document.&quot; + formName + &quot;.submit()&quot;);

but that doesn't do anything. There's no more error when I click on the print link, but the browser doesn't do anything either. It just stops.


 
Hi onpnt ...

I've got it to work now ... I scrapped the javascript function and just created a new url for each print label:
Code:
<a style=&quot;color:black&quot; href=&quot;javascript:document.printInfo<%=rsInfo(&quot;WOID&quot;)%>.submit();&quot;>Print</a>
Thanks for all your help, I really appreciate it. You really helped me move along.

Kevin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top