Solved

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

Posted on 2012-04-11
7
255 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 167 total points
ID: 37836408
Do you mean something like this jsfiddle.
0
 
LVL 9

Assisted Solution

by:Sar1973
Sar1973 earned 333 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 9

Assisted Solution

by:Sar1973
Sar1973 earned 333 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
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)
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

895 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now