Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 219
  • Last Modified:

remove duplicate from my list

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
lulu50
Asked:
lulu50
  • 8
  • 8
1 Solution
 
GaryCommented:
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
 
lulu50Author Commented:
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
 
GaryCommented:
What version of jquery are you using
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
lulu50Author Commented:
jquery-1.10.2.min.js
0
 
lulu50Author Commented:
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
 
GaryCommented:
What browser are you using?
Try the attached test page.
ee-remove.php
0
 
GaryCommented:
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
 
lulu50Author Commented:
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
 
GaryCommented:
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
 
lulu50Author Commented:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
0
 
GaryCommented:
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
 
GaryCommented:
Ok scrap that, just checked and .filter is not included til IE9

Be back shortly.
0
 
lulu50Author Commented:
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
 
GaryCommented:
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
 
lulu50Author Commented:
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
 
lulu50Author Commented:
Excellent ++ lol
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 8
  • 8
Tackle projects and never again get stuck behind a technical roadblock.
Join Now