copying entire form objects to another form??

Discussion in 'Javascript' started by Son KwonNam, Jan 11, 2006.

  1. Son KwonNam

    Son KwonNam Guest

    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.
    Son KwonNam, Jan 11, 2006
    #1
    1. Advertising

  2. Son KwonNam

    RobG Guest

    Son KwonNam wrote:
    > 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');



    --
    Rob
    RobG, Jan 11, 2006
    #2
    1. Advertising

  3. Son KwonNam

    Evertjan. Guest

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


    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
    Evertjan., Jan 11, 2006
    #3
  4. Son KwonNam

    RobG Guest

    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.


    --
    Rob
    RobG, Jan 11, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Framework fan

    Copying an entire solution

    Framework fan, Feb 29, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    445
    Framework fan
    Mar 2, 2004
  2. Jared Wiltshire
    Replies:
    8
    Views:
    411
    Ian Collins
    Aug 7, 2006
  3. 7stud
    Replies:
    11
    Views:
    669
    Dennis Lee Bieber
    Mar 20, 2007
  4. Rob R. Ainscough
    Replies:
    3
    Views:
    309
    Rob R. Ainscough
    Jun 14, 2005
  5. Replies:
    7
    Views:
    102
    James Edward Gray II
    Jul 4, 2005
Loading...

Share This Page