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 to the CF scene
    Join Date
    Feb 2012
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Manipulate array input

    Hi

    I have problem to manipulate my form with array.
    I want to copy my input from one input to other input
    but it didnt work.

    i did explore the usage of document.myForm.feed[3].value
    but it gave me error.

    Pleaseee help?
    Thanks


    script sample:
    <form name=myForm>
    <input name=feed[] onBlur=duplicate(this)>
    <input name=feed[] onBlur=duplicate(this)>
    <input name=feed[] onBlur=duplicate(this)>
    <input name=feed[] onBlur=duplicate(this)>
    <input name=feed[] onBlur=duplicate(this)>
    <input name=feed[] onBlur=duplicate(this)>
    <input name=feed[] onBlur=duplicate(this)>
    <input name=feed[] onBlur=duplicate(this)>

    <input name=copier[] onBlur=sendback(this)>
    <input name=copier[] onBlur=sendback(this)>
    <input name=copier[] onBlur=sendback(this)>
    <input name=copier[] onBlur=sendback(this)>
    <input name=copier[] onBlur=sendback(this)>
    <input name=copier[] onBlur=sendback(this)>
    <input name=copier[] onBlur=sendback(this)>
    <input name=copier[] onBlur=sendback(this)>
    <input name=copier[] onBlur=sendback(this)>
    </form>



    <SCRIPT>
    function duplicate(info)
    {
    //this function should copy 'info' to copier input
    //with the same element location
    //eg: feed[3] will copy to copier[3], feed[5] will copy to copier[5]
    //(can be any element insert by user)

    // the task would be:
    // 1. to get which element number has been inserted
    // 2. to get the origin text value
    // 3. to write the same element position for copier

    }


    function sendback(info)
    {
    //this function should copy 'info' to feed input
    //with the same element location
    //copier[2] will copy to feed[2], copier[3] will copy to feed[3]
    //(can be any element insert by user)
    }
    </SCRIPT>

  • #2
    New Coder
    Join Date
    Feb 2012
    Location
    England
    Posts
    77
    Thanks
    0
    Thanked 12 Times in 11 Posts
    If you want to copy form value to another form value you could use something like this.
    Code:
    document.form['formname']['input1name'].value=document.forms['formname']['input2name'].value
    Also use CODE tags

  • #3
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,535
    Thanks
    3
    Thanked 513 Times in 500 Posts
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    
    <head>
      <title></title>
    <script language="JavaScript" type="text/javascript">
    /*<![CDATA[*/
    
    function duplicate(obj,nme){
     var frm=obj.form,ipsf=frm[obj.name],ipst=frm[nme],z0=0;
     for (;z0<ipsf.length;z0++){
      if (ipsf[z0]==obj&&ipst[z0]){
       ipst[z0].value=ipsf[z0].value;
       break;
      }
     }
    }
    /*]]>*/
    </script></head>
    
    <body>
    <form name=myForm>
    <input name=feed[] onBlur=duplicate(this,'copier[]')>
    <input name=feed[] onBlur=duplicate(this,'copier[]')>
    <input name=feed[] onBlur=duplicate(this,'copier[]')>
    <input name=feed[] onBlur=duplicate(this,'copier[]')>
    <input name=feed[] onBlur=duplicate(this,'copier[]')>
    <input name=feed[] onBlur=duplicate(this,'copier[]')>
    <input name=feed[] onBlur=duplicate(this,'copier[]')>
    <input name=feed[] onBlur=duplicate(this,'copier[]')>
    <br />
    <input name=copier[] onBlur=duplicate(this,'feed[]')>
    <input name=copier[] onBlur=duplicate(this,'feed[]')>
    <input name=copier[] onBlur=duplicate(this,'feed[]')>
    <input name=copier[] onBlur=duplicate(this,'feed[]')>
    <input name=copier[] onBlur=duplicate(this,'feed[]')>
    <input name=copier[] onBlur=duplicate(this,'feed[]')>
    <input name=copier[] onBlur=duplicate(this,'feed[]')>
    <input name=copier[] onBlur=duplicate(this,'feed[]')>
    <input name=copier[] onBlur=duplicate(this,'feed[]')>
    </form>
    
    
    </body>
    
    </html>
    Vic

    God Loves You and will never love you less.

    http://www.vicsjavascripts.org/Home.htm

    If my post has been useful please donate to http://www.operationsmile.org.uk/

  • Users who have thanked vwphillips for this post:

    senarai (02-21-2012)

  • #4
    New to the CF scene
    Join Date
    Feb 2012
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Smile

    thank coldFusion & vwphillips

    i copy & paste the whole vwphillips
    and it works perfectly..


    to simplify the script, i remove the CDATA
    ..and works!

    Hopefully it doesnt create fatal error

    again thanks.. :-)


  •  

    Tags for this Thread

    Posting Permissions

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