Need help!! child and parent window.

Hi,

I have a parent page where I have Selected group list box on it.  The user can filter the data by opening a child page when they are done from their selection and click on the button to add.  the parent group list should get the data from the child page.  

Please, see the image for more detail.

My code so far.
Move the data
function AddtotheList()
{
	$( ".ShowHideAddButton" ).show();
		var SelectedSeg=new Array();
		var SelectedGroup=new Array();
		var dropdownGroup = $("#DispSelectedGroupBox");
		
		$('#DispGroupList option:selected').each(function() {
    			vals = $(this).val()
    			vals=vals.split(",")
           
    			SelectedSeg.push(vals[0])
				SelectedGroup.push(vals[1])
   		})
        SelectedSeg = $.unique( SelectedSeg );
        SelectedGroup = $.unique( SelectedGroup );

		//here how am I going to send the data to the parent page?
		//the dropdown list at the parent page is called "DispSelectedGroupBox"
		//dropdownGroup.html( data );
		//$('#DispSelectedGroupBox').append(value);

                //window.opener.$("#DispSelectedGroupBox").val(SelectedSeg);
                //window.opener.$("#DispSelectedGroupBox").val(SelectedGroup);
}

Open in new window

lulu50Asked:
Who is Participating?
 
GaryConnect With a Mentor Commented:
So you should be using something like this.

function AddtotheList()
{
	$( ".ShowHideAddButton" ).show();
		var SelectedSeg=new Array();
		var SelectedGroup=new Array();
		var dropdownGroup = $("#DispSelectedGroupBox");
		var options="";
		$('#DispGroupList option:selected').each(function() {
    			vals = $(this).val()
    			vals=vals.split(",")
           
			options+='<option value="'+vals[0]+','+vals[1]'" data-GroupNumber="'+vals[2]+'">'+vals[2]+'</option>';

   		})

                window.opener.$("#DispSelectedGroupBox").val(options);
}

Open in new window

0
 
GaryCommented:
What is that? A textarea, dropdown?
0
 
lulu50Author Commented:
Hi Cathal!!!!!!1

it is a select

         <select name="DispSelectedGroupBox" id="DispSelectedGroupBox" size="180" multiple="multiple" class="SearchBySelect5"  style="height:100px; width:250px;background-color:#f8fafc;"> </select>

the option should return the data like this 

<option value="#SegmentID#,#GroupNumber#" data-GroupNumber="#GroupNumber#" >#GroupName#</option>

Open in new window

0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
GaryCommented:
Are you wanting to append or replace what is already there?
I'm not sure which array you are wanting to pass to it but you should get the idea

window.opener.$("#DispSelectedGroupBox").append("<option>"+SelectedSeg.join("</option><option>")+"</option>");

Open in new window

0
 
GaryCommented:
I don't know what #SegmentID#, #GroupNumber# and #GroupNumber relate to...???
0
 
lulu50Author Commented:
I just want to append



Cathal,

the option should look like this

<option value="#SegmentID#,#GroupNumber#" data-GroupNumber="#GroupNumber#" >#GroupName#</option>

Open in new window


window.opener.$("#DispSelectedGroupBox").append("<option>"+SelectedSeg.join("</option><option>")+"</option>");

Open in new window


so is this correct?

window.opener.$("#DispSelectedGroupBox").append("<option>"+SelectedSeg+SelectedGroup.join("</option><option>"+SelectedName)+"</option>");

Open in new window

0
 
GaryCommented:
No
What do #SegmentID#, #GroupNumber# and #GroupNumber relate to...???
0
 
lulu50Author Commented:
Cathal,

this is how the dropdown list on the parent page get populated

<option value="#SegmentID#,#GroupNumber#" data-GroupNumber="#GroupNumber#" >#GroupName#</option>

$('#DispGroupList option:selected').each(function() {
    			vals = $(this).val()
    			vals=vals.split(",")
           
    			SelectedSeg.push(vals[0])
				SelectedGroup.push(vals[1])
				SelectedName.push(vals[2])
   		})
        SelectedSeg = $.unique( SelectedSeg );
        SelectedGroup = $.unique( SelectedGroup );
		SelectedName = $.unique( SelectedName );

#SegmentID# is the SelectedSeg 
#GroupNumber# is the SelectedGroup 
#GroupName# is the SelectedName 

so 

window.opener.$("#DispSelectedGroupBox").append("<option>"+SelectedSeg+SelectedGroup.join("</option><option>"+SelectedName)+"</option>");

I think I need some loop because SegmentID is a list of array the same with GroupNumber and GroupName

Open in new window

0
 
lulu50Author Commented:
I am doing something wrong but not sure what it is


window.opener.$("#DispSelectedGroupBox").append("<option data-GroupNumber=" + SelectedGroup + " value="+SelectedSeg + "," + SelectedGroup +">"+SelectedName.join("</option><option>")+"</option>");

I am getting this output

<option data-GroupNumber="71472value=4,71472">
Text - URMBT FORD PPO

Open in new window

0
 
GaryCommented:
Well this is not going to really work since you are making the arrays unique, how to know which SegmentID, GroupNumber and GroupName belong to each other?
0
 
lulu50Author Commented:
I think in this case I should only have one array instead of three separate one

$('#DispGroupList option:selected').each(function() {
    			vals = $(this).val()
    			vals=vals.split(",")
           
    			SelectedDatapush(vals[0],vals[1],vals[2])

   		})
        SelectedDatapush= $.unique( SelectedDatapush);

Open in new window


something like this?
0
 
lulu50Author Commented:
this is how it should send the data.

window.opener.$("#DispSelectedGroupBox").append("<option value="+SelectedSeg + "," + SelectedGroup +" data-GroupNumber=" + SelectedGroup + ">"+SelectedName.join("</option><option>")+"</option>");

Open in new window

0
 
GaryCommented:
Are the arrays (SelectedSeg, SelectedGroup, SelectedName) used for anything else?
It would make more sense to just build the OPTIONS as they are selected in the child.
0
 
lulu50Author Commented:
I agree! they should get populated directly.

no, they are not used of anything else.

maybe something like this: (It's wrong but I am trying)

hmmm but I do want to remove any duplicate from the list

function AddToTheList()
{
		var SelectedSeg=new Array();
		var SelectedGroup=new Array();
		var SelectedName=new Array();	
		$('#DispGroupList option:selected').each(function() {
    			vals = $(this).val()
    			vals=vals.split(",")
           
		   window.opener.$("#DispSelectedGroupBox").append("<option value="+SelectedSeg.push(vals[0]) + "," + SelectedGroup.push(vals[1]) +" data-GroupNumber=" + SelectedGroup + ">"+SelectedName.push(vals[2]).join("</option><option>")+"</option>");
		
   		})
}

Open in new window

0
 
lulu50Author Commented:
I have syntax error on this line

options+='<option value="'+vals[0]+','+vals[1]'" data-GroupNumber="'+vals[2]+'">'+vals[2]+'</option>';
0
 
lulu50Author Commented:
fixed it now testing
0
 
lulu50Author Commented:
hmmm,

I have the values but it's not appending to the parent listbox.

so, it's not appending the data. hmmm
0
 
lulu50Author Commented:
I changed it to this and it works

   window.opener.$("#DispSelectedGroupBox").append(options);
0
 
GaryCommented:
Yeah small syntax error.
0
 
lulu50Author Commented:
Thank you Gary!!!!!!!!!!  for one million and one times lol
0
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.