Cloning Complete Forms

M

Mister Joe

I'm trying to use javascript to clone a form but have hit a wall. I
have a form in a table row and need to copy the form as well as the
table elements:
<table>
<tr id = "foo"><form><td><input /><</td></form></td>
</table>
foo.firstChild.length = 1
after copy:
<table>
<tr id = "foo"><form><td><input /><</td></form></td>
<tr id = "bar"><form><td><input /><</td></form></td>
</table>
foo.firstChild.length = 0
When I copy the table row as well as the form elements it's seems like
the elements are loosing their association with the form. Is there
some extra step that needs to be taken? I thought about cloning the
input element nodes after I rename them and appending the clone to the
form tag but that would result in having duplicate elements on the
page. Any suggestions would be appreciated.
 
J

jamie.ly

what is your method of copy?

let's say you have

<table>
<tr id = "foo"><form><td><input /><</td></form></td>
</table>
</div>

<div id='clone'>
</div>

<script>
document.getElementById ('clone').innerHTML = document.getElementById
('table_parent').innerHTML;
</script>

should clone everything automatically.
 
D

David Mark

what is your method of copy?

let's say you have

You've got some noise in there.
</div>

<div id='clone'>
</div>

<script>
document.getElementById ('clone').innerHTML = document.getElementById
('table_parent').innerHTML;
</script>

should clone everything automatically.

But the example has an element with an ID ("foo") inside. I haven't
tried it, but having two foo's in the document can't be a good thing.
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,071
Latest member
MetabolicSolutionsKeto

Latest Threads

Top