Click to See Complete Forum and Search --> : Form duplication.


Dave_NI
11-21-2003, 08:49 AM
Long time reader, first time poster.

I have a problem. I have a form in an HTML page, when the user populates the form I need to be able to (on click of a link) open a new window with the same page in it with the form populated.

Reason is that my app (built in Struts/Java) needs a print page. With the page in its current state, it is too wide to be printed. So I put some logic in which hides certain parts of the page (side nav bar, head-footer) when a parameter is on the URl.

This all works fine, I have some script which gets the current url and opens a window with the parent url in it with the additional parameter. The problem occurs when its a form, as a new request is being sent to the server, the page opens with a fresh, blank form.

Is their any way to pass the form details over the request and populate the new form (which is identical) with it? Or is their some way of associating the form in the child window with the one in the parent?

Due to business requirements its not very flwxible, I am looking for a generic way as there are alot of forms.

Anyone got any thoughts?

Cheers

Dave

fredmv
11-21-2003, 10:58 AM
Welcome to the forums Dave!

I read your post over a few times and I believe I understand what you're trying to do. So you're building a page using JSP, I believe, and you want to make a link in which opens a new window with an exact copy of a form, and only the form -- no other page contents -- from the parent window in the child window -- form values and all. If this is the case, which I believe it is, I just put together a script which does exactly this.

You can see the script in action here: http://www.fredvaughn.org/demo/form/.

I hope that helps you out.

Dave_NI
11-24-2003, 03:23 AM
My faith in humanity (and Webdeveloper.com) has been renewed yet again... this is exactly what I needed.

I had tried to write something similar but I get frustrated with trying to develop JavaScript, its probably because I dont have the write debugging environment.

Thanks for the help, thats several drinks I owe u :)

Dave_NI
11-24-2003, 06:20 AM
Another quicky...

Can you pass a document across a request so it can be referenced by a newly opened window?

Dave_NI
11-24-2003, 08:39 AM
Scrap that last one, its all sorted.

You example was the inspiration for the following

var childForm = document.forms[0];
var parentForm = window.opener.document.forms[0];

if (parentForm != null)
{
for(i=0; i<parentForm.elements.length; i++)
{
childForm.elements[i].value = parentForm.elements[i].value;
}
}

This code is only executed on the onload of the child window.

Bit annoying that a couple of lines represents 2 days work but what the hell... it works and its generic to all screens.

Thanks.

fredmv
11-24-2003, 09:12 AM
You're welcome, Dave. :D

ray326
11-24-2003, 11:34 AM
Consider using CSS to hide the things you don't want in a printed version. No special page or popup junk required.