Solved

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

Posted on 2014-03-07
12
380 Views
Last Modified: 2014-03-07
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

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

Expert Comment

by:Gary
ID: 39912898
Would it not make sense to just replace whatever is there or are there values coming from somewhere else?
0
 

Author Comment

by:lulu50
ID: 39912931
no, it shouldn't replace whatever is there.
duplicate
0
 

Author Comment

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

0
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
ID: 39913011
That's pretty much what I was going to do, but I am using the value

		$('#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>';
			}

   		})

Open in new window

0
 

Author Comment

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

0
 
LVL 58

Expert Comment

by:Gary
ID: 39913063
Missing the closing bracket

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

Open in new window

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

 

Author Comment

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

Author Comment

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

Author Closing Comment

by:lulu50
ID: 39913105
I selected the wrong one maybe

this is the correct answer
0
 

Author Comment

by:lulu50
ID: 39913147
oh, I did select the wrong one.

please, admin fix it for me.
0
 
LVL 58

Expert Comment

by:Gary
ID: 39913152
You selected the answer, its fine now.
0
 

Author Comment

by:lulu50
ID: 39913159
oh good thank you Gary
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction Got endorsements from your clients?  Great!  There is almost nothing better than word-of-mouth advertising.  But how can you do that on the internet?  Sure you can make a page for endorsement quotations and list them all, but who is …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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)
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…

910 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

21 Experts available now in Live!

Get 1:1 Help Now