Solved

remove duplicate from my list

Posted on 2014-03-05
16
207 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

790 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