?
Solved

remove duplicate from my list

Posted on 2014-03-05
16
Medium Priority
?
212 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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
 
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 2000 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
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…
Suggested Courses

771 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