Solved

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

Posted on 2009-05-08
9
341 Views
Last Modified: 2012-05-06
Hi
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>
  <tr>
    <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>
 </tr><tr>
    <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>
</tr>
</table

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.
PLUS
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

Brian
// 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
                continue;
            }else{
                strRow += (strRow==''?'':', ') + tr.cells[j].childNodes[0].value;
            }
        }
        str += (str==''?'':'\n') + strRow;
    }
}
 
function save(){
    parseInput();
    var myparent = window.opener;
    myparent.passback(str);
    window.close();
}
 
 
// 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

0
Comment
Question by:windmillway43
  • 4
  • 3
9 Comments
 

Author Comment

by:windmillway43
ID: 24338314
Just for info, Line 2 of function parseInput() in the Code Snippet above can be ignored.
Brian
0
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 24369924
Brian,
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. :)
bol
0
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 24369952
>> 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.
bol
 
0
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 

Author Comment

by:windmillway43
ID: 24370259
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>

Brian
0
 

Author Comment

by:windmillway43
ID: 24371816
bol,
>> 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.

Brian

0
 

Accepted Solution

by:
windmillway43 earned 0 total points
ID: 24380742
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.
0
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 24381007
Brian,
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.
bol
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

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 benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
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)

825 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