Solved

Need help!! child and parent window.

Posted on 2014-03-06
20
315 Views
Last Modified: 2014-03-07
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

0
Comment
Question by:lulu50
  • 12
  • 8
20 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 39910274
What is that? A textarea, dropdown?
0
 

Author Comment

by:lulu50
ID: 39910284
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
 
LVL 58

Expert Comment

by:Gary
ID: 39910295
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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 58

Expert Comment

by:Gary
ID: 39910310
I don't know what #SegmentID#, #GroupNumber# and #GroupNumber relate to...???
0
 

Author Comment

by:lulu50
ID: 39910330
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
 
LVL 58

Expert Comment

by:Gary
ID: 39910334
No
What do #SegmentID#, #GroupNumber# and #GroupNumber relate to...???
0
 

Author Comment

by:lulu50
ID: 39910389
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
 

Author Comment

by:lulu50
ID: 39910434
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
 
LVL 58

Expert Comment

by:Gary
ID: 39910435
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
 

Author Comment

by:lulu50
ID: 39910446
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
 

Author Comment

by:lulu50
ID: 39910481
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
 
LVL 58

Expert Comment

by:Gary
ID: 39910497
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
 

Author Comment

by:lulu50
ID: 39912460
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
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
ID: 39912557
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
 

Author Comment

by:lulu50
ID: 39912570
I have syntax error on this line

options+='<option value="'+vals[0]+','+vals[1]'" data-GroupNumber="'+vals[2]+'">'+vals[2]+'</option>';
0
 

Author Comment

by:lulu50
ID: 39912593
fixed it now testing
0
 

Author Comment

by:lulu50
ID: 39912609
hmmm,

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

so, it's not appending the data. hmmm
0
 

Author Comment

by:lulu50
ID: 39912611
I changed it to this and it works

   window.opener.$("#DispSelectedGroupBox").append(options);
0
 
LVL 58

Expert Comment

by:Gary
ID: 39912615
Yeah small syntax error.
0
 

Author Closing Comment

by:lulu50
ID: 39912785
Thank you Gary!!!!!!!!!!  for one million and one times lol
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

803 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