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: 184
  • Last Modified:

Clear my list

Hi,

I have this jquery that it's not clearing my list before it populate it with a new data.

list = '';  // this is not working

it keeps the previous selection that I want to be removed.

Something is wrong with the code but I'm not sure how to solve it.

 function DetailDialog(w, h,type)
	 {	
		w = 820;
		var left = (screen.width - w) / 2;
        var top = (screen.height - h) / 4; 

	  	var FromDate = $("#GetDateFrom").val();
		var ToDate = $("#GetDateTo").val();

        if (jQuery.cookie('CookieDateFromRpt')){
			$.removeCookie("CookieDateFromRpt");
		}
			$.cookie('CookieDateFromRpt', FromDate, { expires: 10 } );
		
		if (jQuery.cookie('CookieGetDateToRpt')){
			$.removeCookie("CookieGetDateToRpt");
		}
			$.cookie('CookieGetDateToRpt', ToDate, { expires: 10 } );
						
	     var GetValType = $('input[name=CategoryType]:checked', '#ReptFrm').val()
		 var SelName = $("#SelectName option");
		 var SelDept = $("#SelectDepartment option");
		 var SelSeg = $("#SelectSegment option");
         var list = '';
		
		if (GetValType == 'Name')
		{
			list = '';
	    $.each(SelName, function (index, value) {
        if ($('#SelectName').length > 0) {
            
            list += $(value).val() + ',' ; 
        }
        });
    
         list = list.substring(0,list.length-1) + '';

		}else if (GetValType == 'Department')
		{
			list = '';
			 $.each(SelDept, function (index, value) {
        if ($('#SelectDepartment').length > 0) {
            
            list += $(value).val() + ',' ; 
        }
        });
    
         list = list.substring(0,list.length-1) + '';
			
			
		}else if (GetValType == 'Segment')
		{
			list = '';
			 $.each(SelSeg, function (index, value) {
        if ($('#SelectSegment').length > 0) {
            
            list += $(value).val() + ',' ; 
        }
        });
    
         list = list.substring(0,list.length-1) + ''; 
		}	
			
			alert(list);
			
        var targetWin = window.open('OpenCloseDetailRpt.cfm?filter=1&TechType=' + type , 'Group' , 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=1, resizable=1, copyhistory=no, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left); 

	 }
	 

Open in new window

0
lulu50
Asked:
lulu50
  • 4
  • 3
1 Solution
 
GaryCommented:
Code looks fine to me
What do you mean by
keeps the previous selection
0
 
lulu50Author Commented:
Gary,

Please, take a look at the picture I only selected one option but my list gives me more numbers
pic2.png
0
 
GaryCommented:
Your code is looping each element in the dropdown
If you are wanting just the selected elements then change your if else block to

	list = ',';
	if (GetValType == 'Name') {
		$(":selected",SelName).each(function(){
			list += $(value).val() + ',';
		})
	}
	else if (GetValType == 'Department') {
		$(":selected",SelDept).each(function(){
			list += $(value).val() + ',';
		})
	}
	else if (GetValType == 'Segment') {
		$(":selected",SelSeg).each(function(){
			list += $(value).val() + ',';
		})
	}
	list = list.substring(1);

	alert(list);

Open in new window

(condensed the repeating code)
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
lulu50Author Commented:
Gary,

my alert message list shows nothing now.

just like in the picture.


 function DetailDialog(w, h,type)
	 {	
		w = 820;
		var left = (screen.width - w) / 2;
        var top = (screen.height - h) / 4; 

	  	var FromDate = $("#GetDateFrom").val();
		var ToDate = $("#GetDateTo").val();

        if (jQuery.cookie('CookieDateFromRpt')){
			$.removeCookie("CookieDateFromRpt");
		}
			$.cookie('CookieDateFromRpt', FromDate, { expires: 10 } );
		
		if (jQuery.cookie('CookieGetDateToRpt')){
			$.removeCookie("CookieGetDateToRpt");
		}
			$.cookie('CookieGetDateToRpt', ToDate, { expires: 10 } );
						
	     var GetValType = $('input[name=CategoryType]:checked', '#ReptFrm').val()
		 var SelName = $("#SelectName option");
		 var SelDept = $("#SelectDepartment option");
		 var SelSeg = $("#SelectSegment option");
         var list = '';
		
		alert(GetValType);
		
		
		list = ',';
	if (GetValType == 'Name') {
		$(":selected",SelName).each(function(){
			list += $(value).val() + ',';
		})
	}
	else if (GetValType == 'Department') {
		$(":selected",SelDept).each(function(){
			list += $(value).val() + ',';
		})
	}
	else if (GetValType == 'Segment') {
		$(":selected",SelSeg).each(function(){
			list += $(value).val() + ',';
		})
	}
	list = list.substring(1);

	alert(list);

        var targetWin = window.open('OpenCloseDetailRpt.cfm?filter=1&TechType=' + type , 'Group' , 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=1, resizable=1, copyhistory=no, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left); 

	 }

Open in new window

pic2.png
0
 
GaryCommented:
Couple of errors in my code

 function DetailDialog(w, h, type) {
     w = 820;
     var left = (screen.width - w) / 2;
     var top = (screen.height - h) / 4;

     var FromDate = $("#GetDateFrom").val();
     var ToDate = $("#GetDateTo").val();

     if (jQuery.cookie('CookieDateFromRpt')) {
         $.removeCookie("CookieDateFromRpt");
     }
     $.cookie('CookieDateFromRpt', FromDate, {
         expires: 10
     });

     if (jQuery.cookie('CookieGetDateToRpt')) {
         $.removeCookie("CookieGetDateToRpt");
     }
     $.cookie('CookieGetDateToRpt', ToDate, {
         expires: 10
     });

     var GetValType = $('input[name=CategoryType]:checked', '#ReptFrm').val()
     var SelName = $("#SelectName");
     var SelDept = $("#SelectDepartment");
     var SelSeg = $("#SelectSegment");


     list = '';
     if (GetValType == 'Name') {
         $(" :selected", SelName).each(function () {
             list += "," + $(this).val();
         })
     } else if (GetValType == 'Department') {
         $(" :selected", SelDept).each(function () {
             list += "," + $(this).val();
         })
     } else if (GetValType == 'Segment') {
         $(" :selected", SelSeg).each(function () {
             list += "," + $(this).val();
         })
     }
     list = list.substring(1);

     alert(list);



     var targetWin = window.open('OpenCloseDetailRpt.cfm?filter=1&TechType=' + type, 'Group', 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=1, resizable=1, copyhistory=no, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);

 }

Open in new window

0
 
lulu50Author Commented:
This is great Gary!!!!!!!

Thank  you for your help!!!!!!!!!
0
 
lulu50Author Commented:
Thank you
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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