Solved

remove duplicate from my list

Posted on 2014-03-05
16
196 Views
Last Modified: 2014-03-06
Hello,

I have a list that I need to remove any duplicate.

SelectedSeg = "5,5,5,5,5,4"

SelectedIndustry = "8690,8690,8690,6320,6320,8630"

SelectedCompany = "279780,275056,116591,108106,108559,278806"

my select instead should be like this:

SelectedSeg = "5,4"

SelectedIndustry ="8690,6320,8630"

SelectedCompany = "279780,275056,116591,108106,108559,278806"
 
Please, see my code:


function setGroupOptions()
	{
		var	SelectedSeg=""	
		var	SelectedIndustry=""	
		var	SelectedCompany=""	
		var dropdownGroup = $("#DispGroupList");
		var GetSelectedCompany = $("#DispCompanyList option:selected");

		$('#DispCompanyList option:selected').each(function() {
    		vals = $(this).val()
    		vals=vals.split(",")
    		SelectedSeg+= "," + vals[0]
			SelectedIndustry += "," + vals[1]
			SelectedCompany += "," + vals[2]
   		})
			SelectedSeg = SelectedSeg.substring(1)
			SelectedIndustry = SelectedIndustry.substring(1)
			SelectedCompany = SelectedCompany.substring(1)
			
		$.get( "filterGroup.cfm?filter=1&SelectedSeg=" + SelectedSeg + "&SelectedIndustry=" + SelectedIndustry + "&SelectedCompany=" + SelectedCompany, function (data) {
			dropdownGroup.html( data );
		});
	}

Open in new window

0
Comment
Question by:lulu50
  • 8
  • 8
16 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 39907411
This seems to work, notice I'm switching to arrays

		var	SelectedSeg=new Array();
		var	SelectedIndustry=new Array();
		var	SelectedCompany=new Array();

		$('#DispCompanyList option:selected').each(function() {
    			vals = $(this).val()
    			vals=vals.split(",")
           
    			SelectedSeg.push(vals[0])
			SelectedIndustry.push(vals[1])
			SelectedCompany.push(vals[2])
   		})
        SelectedSeg = SelectedSeg.filter(function(el, position) {
            return SelectedSeg.indexOf(el) == position;
        })
        SelectedIndustry = SelectedIndustry.filter(function(el, position) {
            return SelectedIndustry.indexOf(el) == position;
        })
        SelectedCompany = SelectedCompany.filter(function(el, position) {
            return SelectedCompany.indexOf(el) == position;
        })

Open in new window

0
 

Author Comment

by:lulu50
ID: 39907475
Hi Cathal,

I have an error

it says "Object doesn't support this property or method"

Object doesn't support this property or method
0
 
LVL 58

Expert Comment

by:Gary
ID: 39907496
What version of jquery are you using
0
 

Author Comment

by:lulu50
ID: 39909112
jquery-1.10.2.min.js
0
 

Author Comment

by:lulu50
ID: 39909156
jQuery 2.x has the same API as jQuery 1.x, but does not support Internet Explorer 6, 7, or 8.  Since IE 6/7/8 are still relatively common, we recommend using the 1.x version unless you are certain no IE 6/7/8 users are visiting the site.

My users uses IE 7/8 so, newer version will not work for me.

I have right now this version: jquery-1.10.2.min.js
0
 
LVL 58

Expert Comment

by:Gary
ID: 39909333
What browser are you using?
Try the attached test page.
ee-remove.php
0
 
LVL 58

Expert Comment

by:Gary
ID: 39909343
Just looked at the screenshot again!
Have you tried running the page in a real browser. Shouldn't be running in quirks mode or IE8 compat mode - this is the likely reason.
0
 

Author Comment

by:lulu50
ID: 39909378
My users are using IE 8 so I have to develop this tool in IE8

I am running the project in real browser. but I have the error above showing.

doesn't support this property or method.
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 58

Expert Comment

by:Gary
ID: 39909389
But disable IE8 compatibility mode. Running IE8 in quirks mode is like running the browser as IE5
What type of DOCTYPE are you using?
0
 

Author Comment

by:lulu50
ID: 39909431
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
0
 
LVL 58

Expert Comment

by:Gary
ID: 39909439
Use
<!DOCTYPE html>

And see if you still get the same error

(Of course come 30 days time they shouldn't even be using the internet with those old (to be) unsupported browsers and you should be looking at enforcing an upgrade to use the site.)
0
 
LVL 58

Expert Comment

by:Gary
ID: 39909465
Ok scrap that, just checked and .filter is not included til IE9

Be back shortly.
0
 

Author Comment

by:lulu50
ID: 39909468
the same error

it gives me this error When the browser tries to read these lines.

  SelectedSeg =  SelectedSeg.filter(function(el, position) {
            return SelectedSeg.indexOf(el) == position;[embed=file 838521]
        })
        SelectedIndustry = SelectedIndustry.filter(function(el, position) {
            return SelectedIndustry.indexOf(el) == position;
        })
        SelectedCompany = SelectedCompany.filter(function(el, position) {
            return SelectedCompany.indexOf(el) == position;
        })

Open in new window

error.png
0
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
ID: 39909489
Well this was easier than expected in jQuery - Go jQuery!

		var SelectedSeg=new Array();
		var SelectedIndustry=new Array();
		var SelectedCompany=new Array();

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

Open in new window

0
 

Author Comment

by:lulu50
ID: 39909723
Wow that's is just beautiful!!!!!

it is GREAT!!!!!!!!

Thank you for all your help.  

I still have one last step on this than I'm good.

I'll post a new post soon.

Thank you again and again and again.

This is great!!!!
0
 

Author Closing Comment

by:lulu50
ID: 39909726
Excellent ++ lol
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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 …
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
The viewer will learn how to dynamically set the form action using jQuery.
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)

705 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

17 Experts available now in Live!

Get 1:1 Help Now