Solved

Need help!! child and parent window.

Posted on 2014-03-06
20
306 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
Comment Utility
What is that? A textarea, dropdown?
0
 

Author Comment

by:lulu50
Comment Utility
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
Comment Utility
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
 
LVL 58

Expert Comment

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

Author Comment

by:lulu50
Comment Utility
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
Comment Utility
No
What do #SegmentID#, #GroupNumber# and #GroupNumber relate to...???
0
 

Author Comment

by:lulu50
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

Author Comment

by:lulu50
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
fixed it now testing
0
 

Author Comment

by:lulu50
Comment Utility
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
Comment Utility
I changed it to this and it works

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

Expert Comment

by:Gary
Comment Utility
Yeah small syntax error.
0
 

Author Closing Comment

by:lulu50
Comment Utility
Thank you Gary!!!!!!!!!!  for one million and one times lol
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Form submit issue 11 52
Jquery Typeahead - where is the source set? 1 13
addressing a specific html page 9 19
ajax form sumbit 3 21
Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
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…
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…

772 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