View Full Version : Getting info from cloned form elements

04-07-2006, 12:24 PM
Hi All,
I've created a page with a form on a row which is duplicated by the user clicking a button if they need to. The duplication works fine, it's just getting the elements from the duplicated form I'm struggling with. I've been told that you can't reference cloned form elements by their names is this true? if so how do you do it?? :confused:

Here's my cloning code

function NewRow(tid,cid,cnu){
var tobj=document.getElementbyId(tid);
var counter=document.getElementbyId(tid).getElementsByTagName('TR').length;
var cobj=document.getElementbyId(cid).getElementsByTagName('TR')[cnu].cloneNode(true);
cobj.getElementsByTagName('form')[0].name = 'n'+counter; //

tid is the destination div for the row and cid is the row which will be cloned.

Many Thanks!

04-08-2006, 05:24 PM
It is partial true. For instance you you clone radio buttons, even if you change dynamically their names, at least in IE they will continue to behavior as they all belong to the same group. In other cases you may use names, but probably you must change all the form's elements' names. See also:


04-10-2006, 12:04 PM
ok, that post is a little higher than the level I'm at, but are you saying when I clone the elements I should give each input element and drop down a unique ID and then reference those?

04-10-2006, 12:09 PM
by default id must be unique on page, so that yes, you must change the id's