/    Sign up×
Community /Pin to ProfileBookmark

Form duplication.

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

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@fredmvNov 21.2003 — 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.
Copy linkTweet thisAlerts:
@Dave_NIauthorNov 24.2003 — 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 ?
Copy linkTweet thisAlerts:
@Dave_NIauthorNov 24.2003 — Another quicky...

Can you pass a document across a request so it can be referenced by a newly opened window?
Copy linkTweet thisAlerts:
@Dave_NIauthorNov 24.2003 — 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.
Copy linkTweet thisAlerts:
@fredmvNov 24.2003 — You're welcome, Dave. ?
Copy linkTweet thisAlerts:
@ray326Nov 24.2003 — Consider using CSS to hide the things you don't want in a printed version. No special page or popup junk required.
×

Success!

Help @Dave_NI spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.23,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...