Passing back a table(array) to a parent page, then process this info on the parent

This question is similar to, but slightly more complex than, Q_24245405.
To which I received a very comprehensive reply from "third"
Thankyou "third"

OK, here is the question:
I have a parent page.
When I click on a button here, I open a pop-up (child) window.
Here I use javascript to dynamically create the following table

<table id="tblSample>
    <td><input id="InputCell_1_1 size="4" value="pid" /></td>
    <td><input id="InputCell_1_2 size="30" value="nam" /></td>
    <td><input id="InputCell_1_3 size="15" value="label" /></td>
    <td><input id="InputCell_2_1 size="4" value="pid" /></td>
    <td><input id="InputCell_2_2 size="30" value="nam" /></td>
    <td><input id="InputCell_2_3 size="15" value="label" /></td>

What I want to do now (with code if poss please) is to parse the same dynamically created table info on the pop-up page, and return it to the parent, and then do the following on the parent
1) Display as a table for viewing (with additional columns for "Add" or "Don't Add" this row)
2) To have the said table info as an "array" for then subsequent parsing into a database when "save" is pressed on the parent"

I am able currently to return the "Text" info to the parent by using the following attached code.
function parseinput() // On the pop-up page
function save () // On the pop-up page
function passback(str)  // On the parent page
Note: ElementId('newindis') currently is a text area.

What I really want this time is to:
a) view the table on the parent (with additional radio items "Add" and "Don't add" for each row
b) have an array of table in a) to be parsed when save is clicked on the parent
c) The array should be in the format   // $cens_pids = array('I1', 'I2' ...etc);
(where 'Ix' is the "pid" column value in the original table)
d) Addtionally parse a second table already on the parent (similar to the aquired table)
This table has "Keep" or "Remove" radio items for each row

I then need to "Save" on the parent and do the following,
a) Remove all rows on second table that have "remove" enabled.
c) Add all rows on first table that have "add" enabled

The Add and Remove functions I know how to deal with.

Please ask any questions for clarity, sorry it is a bit complex
However the previous questions answer from "third" should help

// 2 Functions already existing on Child (pop-up) window
function parseInput() {
    var NoteTitl = document.getElementById('Titl');
    str = "";
    var tbl = document.getElementById('tblSample');
    for(var i=1; i<tbl.rows.length; i++){ // start at i=1 because we need to avoid header
        var tr = tbl.rows[i];
        var strRow = '';
        for(var j=1; j<tr.cells.length; j++){
            if (j==4 || j==3) {
                // dont show col	 0 index
                // miss out col 4	delete button
                // miss out col 3	relationship
                strRow += (strRow==''?'':', ') + tr.cells[j].childNodes[0].value;
        str += (str==''?'':'\n') + strRow;
function save(){
    var myparent = window.opener;
// 1 Function already existing on Parent window 
function passback(str) {
    var memo = document.getElementById('newindis');
    memo.value = str;
// Note: ElementId('newindis') currently is a text area on the Parent window..

Open in new window

Who is Participating?
windmillway43Author Commented:
While waiting, I modified the parser function, and have enabled the creation of a table here too.
It still needs some work, so I think I will close this question, and spend some more time myself.
windmillway43Author Commented:
Just for info, Line 2 of function parseInput() in the Code Snippet above can be ignored.
b0lsc0ttIT ManagerCommented:
It seems like this is quite the project.  Of course maybe I missed the specific question here with all of the details so let me know if I am wrong.  Otherwise I suggest you see if you can break this into parts, especially if you want code.  It is one thing to provide general advise on doing some project.  However to help with actually doing it an EE question should just be specific (i.e. how can I send the table info to the parent page).
Let me know if I have misread this but if I am right then try to narrow down what you need help with here.  It sounds like something that can be done but all of those items are a bit of work and time, especially when we don't have much code and aren't just fixing a bug or two.  Let me know if you don't know what I mean by any of this and I hope it helps. :)
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

b0lsc0ttIT ManagerCommented:
>> What I want to do now (with code if poss please) is to parse the same dynamically created table info on the pop-up page, and return it to the parent,  <<
To help get started with the specifics and maybe breaking this up is it possible to keep the info from when the table is made?  Working on just the part of the question above it would seem better to use the info used to make the table than to parse it.  If the array exists to make the table then use it to send the info to the parent.  It is pretty easy to do and would save work of reading the table and getting the info.
Let me know how this helps and, if you want to work on this part here, please provide details.
windmillway43Author Commented:
Hi bol, good to talk to you.

>> To help get started with the specifics and maybe breaking this up is it possible to keep the info from when the table is made?

The whole idea is to link individual id's in a database, to a media object (also in the database)
A MYSQL link table already exists with this info.
Currently one can search  one by one and add each individua as a link (a bit laborious)l.
I want to create a list of people and then save this list as links to the media object OK?
I also want the possibility to remove existing individual links too.
Therefore there will be just one table of existing links when we open the parent
(This I have already)

I want a second visible table of individuals to be added to the list

Note at the moment I can pass the parsed info from the child into a text field in the parent as I have indicated in my code.
This code I received from "third"

Yes this table will exist in the "child" as it is dynamically created there by clicking on a navigator with names in the "child" window. It is a table with the id "tblSample" It is this table that I wish to:
a: display as a table in the parent when the child is closed (ie you have finished adding names)
b. then when the parent is saved, I want to add just the "id" column into an array which can be looped with a function I already have, to enter these vaues into a database.

The table must be viewable in the parent, the id and the name, together with two additional colums of  "Add" and "dont add" (perhaps a radio button)

In the parent will be another table which will show existing links as I have said above.
However when adding the two tables to the database, I want to take note of existing items that need to be removed, and an option to "Dont Add" items from the child table dynamically created.

Is this any clearer for a rather complex requirement <grin>

windmillway43Author Commented:
>> If the array exists to make the table then use it to send the info to the parent.  It is pretty easy to do and would save work of reading the table and getting the info

To make sure that I think Iunderstand what you are asking. Let me explain a little further.
The table in the child (tblSample) is created row by row with a JavaScript function which I call
function insertRowToTable(pid, nam, label, gend, cond, yob, age, YMD, occu, birthpl)
This function is also used elsewhere in my program to create a textual Census Item.
In this case we are discussing, I only need the pid and nam (name) parameters.

Each row is created by clicking on a name in a navigator which is itself a list of names constructed using PHP & mysql calls.
Because "tblSample" is dynamically constructed it could be one row, or even seventeen rows, it all depends how many names you have clicked.

So honestly I think it may be simpler to modify and use the parser above and create an array this way perhaps to end up with (as an example) an array in a hidden field as so :
i1 => Fred Smith, i2 => Jane Smith. etc

The only thing that needs to be done in this case is to recreate a visible table on the parent of the id and names as follows (The Add  and dont Add would be radio buttons)
id  Name          Add  Dont Add
i1  Fred Smith  x
i2  Jane Smith  x

The table only needs to visible as feedback to the user, with a choice to add or NOT.
The actual final "SAVE" (which I already know how to do) only uses the id in each case.

I know it sounds silly maybe going from table to array and back to table again by parsing, but as you see the parsing code is only 10 lines. The dynamic table creator is about 300 lines so I do not want to recreate this again on another page if possible.


b0lsc0ttIT ManagerCommented:
Thanks for letting me know.  It seemed I was going to have some time and Internet access for this tonight but I guess it is too late.  Thanks for the update.  If you do open a new question and want to attract my attention to it then feel free to post a comment here with the new question's URL.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.