Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Sep 2005
    Posts
    45
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Getting info from cloned form elements

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

    Here's my cloning code
    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
    Last edited by daffy_dowden; 04-07-2006 at 01:32 PM.

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    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/showthre...ighlight=clone
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #3
    New Coder
    Join Date
    Sep 2005
    Posts
    45
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?

  • #4
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    by default id must be unique on page, so that yes, you must change the id's
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •