By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,986 Members | 1,944 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,986 IT Pros & Developers. It's quick & easy.

copying entire form objects to another form??

P: n/a
Hello,
When there a two forms like the follosings,

<form name="source">
<input name="a..." value=".." ..>
<input name="a..." value=".." ..>
<input name="a..." value=".." ..>
<input name="a..." value=".." ..>
</form>

<form name="target" />

As you see target form has no child elements and source form has *a lot*
of elements.
Is this possbile to copy entire objects of source form to target form?
(I don't mean copying filed by field)

Regards,
KwonNam.
Jan 11 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Son KwonNam wrote:
Hello,
When there a two forms like the follosings,

<form name="source">
<input name="a..." value=".." ..>
<input name="a..." value=".." ..>
<input name="a..." value=".." ..>
<input name="a..." value=".." ..>
</form>

<form name="target" />

As you see target form has no child elements and source form has *a lot*
of elements.
To be valid, your form must contain at least one block or script element
and have an action attribute. It must also have a closing tag, your
markup seems to infer an empty XHTML element.

<form name="target" action=""><p></p></form>

<URL:http://www.w3.org/TR/html4/interact/forms.html#edef-FORM>
Forms /should/ use an ID attribute rather than a name, but I guess name
is far more convenient for what you are attempting.

Is this possbile to copy entire objects of source form to target form?
(I don't mean copying filed by field)

function cloneForm(srcName, tgtName)
{
var srcForm = document.forms[srcName];
var tgtForm = document.forms[tgtName];

if (tgtForm && srcForm && srcForm.cloneNode) {
var cpyForm = srcForm.cloneNode(true);
cpyForm.name = tgtForm.name;

// Change any ID attributes that were copied to
// the clone before adding it to the document

tgtForm.parentNode.replaceChild(cpyForm, tgtForm);
}
}
Call it with:

cloneForm('source', 'target');

--
Rob
Jan 11 '06 #2

P: n/a
Son KwonNam wrote on 11 jan 2006 in comp.lang.javascript:
When there a two forms like the follosings,

<form name="source">
<input name="a..." value=".." ..>
<input name="a..." value=".." ..>
<input name="a..." value=".." ..>
<input name="a..." value=".." ..>
</form>

<form name="target" />

As you see target form has no child elements and source form has *a
lot* of elements.
Is this possbile to copy entire objects of source form to target form?
(I don't mean copying filed by field)


<div id='container1'>
Here:
<form name="mySource">
<input name="a" value=".." ><br>
<input name="b" value=".." ><br>
<input name="c" value=".." ><br>
<input name="d" value=".." >
</form>
</div>

<div id='container2'>

</div>

<script type="text/JavaScript">

var c1 = document.getElementById('container1')
var c2 = document.getElementById('container2')
c2.innerHTML = c1.innerHTML.replace('mySource','myTarget')

</script>

This does not work if you delete the text "Here:".

Why ????
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jan 11 '06 #3

P: n/a
Evertjan. wrote:
[...]
<div id='container1'>
Here:
<form name="mySource">
<input name="a" value=".." ><br>
<input name="b" value=".." ><br>
<input name="c" value=".." ><br>
<input name="d" value=".." >
</form>
</div>

<div id='container2'>

</div>

<script type="text/JavaScript">

var c1 = document.getElementById('container1')
var c2 = document.getElementById('container2')
c2.innerHTML = c1.innerHTML.replace('mySource','myTarget')

</script>

This does not work if you delete the text "Here:".

Why ????


Dunno, it works fine regardless in Safari, Firefox and IE 5.2 on Mac.
--
Rob
Jan 11 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.