Link to home
Start Free TrialLog in
Avatar of lulu50
lulu50Flag for United States of America

asked on

Gary!!!! check if the data exist in the dropdown list

Hi,

I need to check if the group number already exist in the parent window drop-down list
before append the data

my code in the child page:

function AddToTheList()
{
		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[1]+'">'+vals[2]+'</option>';

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

Open in new window



what I need is to check if #DispSelectedGroupBox has the GroupNumber already
before appending the data to it.  

so something like this:  

function AddToTheList()
{
		var SelectedSeg=new Array();
		var SelectedGroup=new Array();	
		var dropdownGroup = $("#DispSelectedGroupBox");
		var options="";
		$('#DispGroupList option:selected').each(function() {
    			vals = $(this).val()
    			vals=vals.split(",")

		$.each(dropdownGroup, function(index, value) {
				if ($('#DispSelectedGroupBox option[data-GroupNumber=' +vals[1] + ']').length > 0)
		{
					alert("Already filtering on " + vals[1]);
			}
			else {
		  options+='<option value="'+vals[0]+','+vals[1]+ '" data-GroupNumber="'+vals[1]+'">'+vals[2]+'</option>';
			}
				});
   		})
		   window.opener.$("#DispSelectedGroupBox").append(options);
}

Open in new window

Avatar of Gary
Gary
Flag of Ireland image

Would it not make sense to just replace whatever is there or are there values coming from somewhere else?
Avatar of lulu50

ASKER

no, it shouldn't replace whatever is there.
User generated image
Avatar of lulu50

ASKER

so something like this maybe.

function AddToTheList()
{
		var SelectedSeg=new Array();
		var SelectedGroup=new Array();	
		var dropdownGroup = $("#DispSelectedGroupBox");
		var selectedGroups = $("#DispSelectedGroupBox option:selected");
		var options="";
		$('#DispGroupList option:selected').each(function() {
    			vals = $(this).val()
    			vals=vals.split(",")

	$.each(selectedGroups, function(index, value) {
		
		if ($('#DispSelectedGroupBox option[data-GroupNumber=' +vals[1] + ']').length > 0)
		{
			alert("Already filtering on " + vals[1]);
			}
			else {
		  options+='<option value="'+vals[0]+','+vals[1]+ '" data-GroupNumber="'+vals[1]+'">'+vals[2]+'</option>';
			}
	});

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

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Gary
Gary
Flag of Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of lulu50

ASKER

getting error on this line

      if(window.opener.$("#DispSelectedGroupBox option[value='"+vals[0]+','+vals[1]+"']").length == 0{


ERROR: Object expected

function AddToTheList()
{
		var SelectedSeg=new Array();
		var SelectedGroup=new Array();	
		var dropdownGroup = $("#DispSelectedGroupBox");
		var options="";
		$('#DispGroupList option:selected').each(function() {
    			vals = $(this).val()
    			vals=vals.split(",")

		if(window.opener.$("#DispSelectedGroupBox option[value='"+vals[0]+','+vals[1]+"']").length == 0{
		{
				options+='<option value="'+vals[0]+','+vals[1]+ '" data-GroupNumber="'+vals[1]+'">'+vals[2]+'</option>';
			}

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

Open in new window

Missing the closing bracket

		if(window.opener.$("#DispSelectedGroupBox option[value='"+vals[0]+','+vals[1]+"']").length == 0){

Open in new window

Avatar of lulu50

ASKER

Gary!!!!!

What can I say.  It is working!!!!!! very very nice.  

Thank you Gary for all your help this is exactly what I need.  

Can't thank you enough. lol lol

I am very very happy with the result..

So, thank you again and again.  

lulu
Avatar of lulu50

ASKER

I've requested that this question be closed as follows:

Accepted answer: 0 points for lulu50's comment #a39913050

for the following reason:

Excellent ++++ for one million and one lol lol
Avatar of lulu50

ASKER

I selected the wrong one maybe

this is the correct answer
Avatar of lulu50

ASKER

oh, I did select the wrong one.

please, admin fix it for me.
You selected the answer, its fine now.
Avatar of lulu50

ASKER

oh good thank you Gary