Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-21-2012, 01:55 PM   PM User | #1
senarai
New to the CF scene

 
Join Date: Feb 2012
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
senarai is an unknown quantity at this point
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>
senarai is offline   Reply With Quote
Old 02-21-2012, 01:59 PM   PM User | #2
Co1dFusion
New Coder

 
Join Date: Feb 2012
Location: England
Posts: 77
Thanks: 0
Thanked 12 Times in 11 Posts
Co1dFusion can only hope to improve
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
Co1dFusion is offline   Reply With Quote
Old 02-21-2012, 02:13 PM   PM User | #3
vwphillips
Senior Coder

 
Join Date: Mar 2005
Location: Portsmouth UK
Posts: 4,355
Thanks: 3
Thanked 458 Times in 445 Posts
vwphillips is a jewel in the roughvwphillips is a jewel in the roughvwphillips is a jewel in the rough
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.uk/

If my post has been useful please donate to http://www.operationsmile.org.uk/
vwphillips is offline   Reply With Quote
Users who have thanked vwphillips for this post:
senarai (02-21-2012)
Old 02-21-2012, 02:44 PM   PM User | #4
senarai
New to the CF scene

 
Join Date: Feb 2012
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
senarai is an unknown quantity at this point
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.. :-)
senarai is offline   Reply With Quote
Reply

Bookmarks

Tags
array

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:09 AM.


Advertisement
Log in to turn off these ads.