copying entire form objects to another form??

S

Son KwonNam

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.
 
R

RobG

Son said:
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');
 
E

Evertjan.

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 ????
 
R

RobG

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top