Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

I am trying to copy info from a group of coloumns to a next group of coloumns

Posted on 2012-04-11
7
Medium Priority
?
267 Views
Last Modified: 2012-04-22
I am trying to copy info from a group of coloumns to a next group of coloumns using a check box. If the user uncheck the check box the coloumns that I copy to would be clear so the user can enter a differentset of info into the colounms.

this is a html form

1. How can I do this

2. what language should I use java script or php to do this

3. can I get some code example.
0
Comment
Question by:1030071002
  • 3
  • 3
7 Comments
 
LVL 20

Assisted Solution

by:Proculopsis
Proculopsis earned 334 total points
ID: 37836408
Do you mean something like this jsfiddle.
0
 
LVL 9

Assisted Solution

by:Sar1973
Sar1973 earned 666 total points
ID: 37836991
If you have a table with rows and columns, you can use Javascript innerHTML or innerText function, combined with "onclick=setContentCB()" event associated to the checkbox and an if function which sets the content you want to display.
Here you got it:
function setContentCB() {
var myCheckName = ["CheckBox1", "CheckBox2", "......"];
var myContent = [["Content1C", "Content2C", "......"], ["Content1U", "Content2U", "......"]];
var myCheckBox;
      for (var k=0;k<myCheckName.length;k++) {
            myCheckBox = document.getElementsByName(myCheckName[k])[0];            if(myCheckBox.checked) {
            document.getElementById("myTable").rows[0].cells                        [k].innerHTML=myContent[0][k];
      } else {
            document.getElementById("myTable").rows[0].cells                        [k].innerHTML=myContent[1][k];
      }
      }
}
See also http://www.w3schools.com/js/tryit.asp?filename=try_dom_tablerow_cells.
0
 

Accepted Solution

by:
1030071002 earned 0 total points
ID: 37838315
Okay maybe I was not clear enough I want to copy the content from one group of colounms to a next group of colounms. Both group of colounms already exists on the form.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 9

Assisted Solution

by:Sar1973
Sar1973 earned 666 total points
ID: 37838694
What do you mean with "group of columns"...? You have, for example, 4+4 columns in one table and you want to:
A. copy 1 to 5, 2 to 6, 3 to 7, 4 to 8 in case "Checked";
B. copy 5 to 1, 6 to 2, 7 to 3, 8 to 4 in case "Unchecked" (even at the same time);
C. (other))
Please post some HTML code corresponding to the area you intend to modify; notice also that innerHTML function can be applied to many elements/tags, but the essential condition is that you have identified them with id="..." and/or name="..." attributes.
Then, replace "myTable" in the above example with the id of the element you want to apply.
If you have different columns in a table with 1 row each (row number 0), then apply to the C columns like this:
 if(myCheckBox.checked) {
        document.getElementById("myTable").rows[0].cells[0].innerHTML = myContent[0][k];
        ..........
        document.getElementById("myTable").rows[0].cells[C].innerHTML = myContent[0][k];
 } else {
        document.getElementById("myTable").rows[0].cells[0].innerHTML = myContent[1][k];
        ..........
        document.getElementById("myTable").rows[0].cells[C].innerHTML = myContent[1][k];
 }
or if you just want to exchange table contents:
if (....)
     document.getElementById("myTable").rows[0].cells[1].innerHTML = document.getElementById("myTable").rows[0].cells[0].outerHTML;
.......
     document.getElementById("myTable").rows[0].cells[C].innerHTML = document.getElementById("myTable").rows[0].cells[C-1].outerHTML;
....else
....
Notice with certain elements such as Text areas you can use inner/outerText instead.
0
 

Author Comment

by:1030071002
ID: 37856931
I had to pay some one to show me what to do.
0
 
LVL 9

Expert Comment

by:Sar1973
ID: 37857111
My solution seems clear enough: if your "group of columns" is a table with name/identified columns and/or cells, the code I have provided should work.
0
 

Author Closing Comment

by:1030071002
ID: 37877344
No solid example and solution
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses

877 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question