• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Quick way to copy form elements from one form into another?

lozina

Lifer
I have a page which has it's own form and 2 iframes which each have their own form.

When the main page submits I want it to copy the form elements from the two iframes into it's main form so that data is including in the request being submitted.

I can access the forms in the iframes but I'm not sure how to copy the form elements... I tried to grab a form element and then call appendChild() on the main form passing the iframe form element but I get an exception about 'could not convert Javascript argument'.

There's gotta be an easy way to do this?
 
Well, just imagine a main page simply like this:

<hmtl>
<form></form>
<iframe name="something" src="something.htm"></iframe>
</html>

and something.htm looks like:

<html>
<form>
<input type="checkbox" name="bleh">
<input type="checkbox" name="bleh">
<input type="checkbox" name="bleh">
</form>
</html>

Now when the main page submits I want those "bleh" elements copied into the main page's form.

I just tried the following code which partially works.. for some reason it's skipping every other element :Q

(I think appendChild is working now because before as a test I tried calling appendChild on a specifically named element but this time I'm pulling them from the elements collection)
 
dang, think I just figured out why it wasn't copying every element... apparently "appendChild" actually SUCKS the element from one place to another, so it's removing it from the form and so it's length is being reduced as I go along. This is the fixed code in case you interested:

 
Back
Top