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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pass div content as parameter

Status
Not open for further replies.

Pichdude

Programmer
Aug 24, 2005
66
SE
Hi,

I am wondering if it is possible to pass the content of div as a request parameter to another page?

If I do this...

Code:
var printDivContent = document.getElementById("testDiv").innerHTML;

<a href="#" onclick="window.open('print.jsp?param=printDivContent', 'Help', 'location=yes,resizable=yes,width=600,height=460,scrollbars');">Print</a>");

...and print out the content of request parameter "param" this is the result on print.jsp:

printDivContent


My intention was of course not to pass printDivContent as a String but instead the variable printDivContent?

Is that possible?

Best regards

Pichdude
 
Hi

Code:
var printDivContent = [red]escape([/red]document.getElementById("testDiv").innerHTML[red])[/red];

<a href="#" onclick="window.open('print.jsp?param=[red]'+[/red]printDivContent, 'Help', 'location=yes,resizable=yes,width=600,height=460,scrollbars');">Print</a>");

Feherke.
 
Yes, that should be valid, but your syntax is wrong. Since printDivContent is a javascript variable, you need to exit the window.open string to insert the variable in.

Code:
<a href="#" onclick="window.open('print.jsp?param=[!]" + printDivContent + "'[/!], 'Help', 'location=yes,resizable=yes,width=600,height=460,scrollbars');">Print</a>");


[monkey][snake] <.
 
Hi

[tt]<a href="#" onclick="window.open('print.jsp?param=" + printDivContent + "',[gray]...[/gray]
[red]------------------------------------^[/red][/tt]
thread216-1370511

Feherke.
 
Is it possible to retrieve a div from the original page (with the print-link) on print.jsp?

I.e. not passing the div-content on a request parameter, instead getting it by using something like getElementById that looks in the original page.

Best regards

Pichdude
 
You can reference the "original page" with window.opener.


So if the div has an id of "cheese" in the original page, you can say

window.opener.document.getElementById("cheese")

[monkey][snake] <.
 
This is assuming that the original page is still loaded in a browser and not closed.

[monkey][snake] <.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top