...

View Full Version : Getting info from cloned form elements



daffy_dowden
04-07-2006, 11:24 AM
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; //
tobj.appendChild(cobj);
}

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

Many Thanks!
Daf

Kor
04-08-2006, 04: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:

http://www.codingforums.com/showthread.php?t=83424&highlight=clone

daffy_dowden
04-10-2006, 11:04 AM
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?

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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum