I have several text boxes in my form. I would like to place a checkbox next to each text box. If I check the box I would like the contents of the corresponding text box to be copied into one big text area (Big Text Area). For example, if I type "apples" into textbox#1 and click the checkbox next to textbox#1, I would like "apples" to be copied to the Big Text Area; then if I type "oranges" into textbox#2 I would like "oranges" to be copied into the Big Text Area and append apples, so the Big Text Area would contain "apples oranges".
I can accomplish the above if I manually type the field names into the function, but this is cumbersome. I would like to have a simple script that changes depending on which input/checkbox calls it.
In the below script the text area named "copyto" is my big text area that I wish to copy into.Upon checking the box under Copy From#1, the function currently copies the text from this box into the "copyto" text area. However, upon checking the box under Copy From#2 I need the function to change to allow copying of the contents of the Copy From#2 box into the "copyto" text area.
here is the jsfiddle to the below: http://jsfiddle.net/33RLk/
<script>
function Copy(f) {
if(f.copyfrom1.checked == true) {
f.copyto.value += '\n' + f.copyfrom.value;
}
}
</script>
<form>
Copy From #1:
<input type="text" name="copyfrom">
<br>
<input type="checkbox" name="copyfrom1" onclick="Copy(this.form)">
<em>Check to copy "Copy From #1" box to "Copy to" box.</em>
<P>
<br>
Copy From #2:
<input type="text" name="copyfromtwo">
<br>
<input type="checkbox" name="copyfrom2" onclick="Copy(this.form)">
<em>Check to copy "Copy From #2" box to "Copy to" box.</em>
<P>
<br>
Copy to:
<textarea name="copyto" cols="25" rows="4">Text</textarea>
</form>