vandan's avatar
Level 13

how to fetch multiple selected checkbox in dropdown using jquery

dropdown edit time not fetch selected value checked in jquery dropdown always return last selected element how to fetch selected checked value in dropdown

here is my code

$(document).on('change','.edit-alert-select-class',function(){
	var eid = $(this).attr('id');
	var splitData = eid.split("-");	
	var fid = $("#fid-"+splitData[2]).val();
	var alertLevel = $( "#edit-level-"+splitData[2]+" option:selected" ).val();
	if(alertLevel != 'client')
	{
		$.ajax({
			type:'POST',
			data:{'_token':'{{csrf_token()}}','alertLevel': alertLevel,'clientId':'{{$client->id}}','fid': fid},
			url:"{{route('findclientsalescenter')}}",
			success:function(response){
				$("#edit-location-"+splitData[2]).empty();
				$.each(response.data.salescenters, function(key,value){
					var vid = value.id;
					var conNumToString = vid.toString().split("");
					if(response.data.selectedsalescenters){
						var salesArray = '';
						if(alertLevel == "salescenter"){
							salesArray = response.data.selectedsalescenters.split(',');
						}else if(alertLevel == "sclocation"){
							salesArray = response.data.selectedsalescenters.split(',');
						}
					}
					if(Array.isArray(salesArray) && salesArray.indexOf(conNumToString) !== 1){
						console.log('1');
						$("#edit-location-"+splitData[2]).append('<option value='+ value.id +'selected>'+ value.name +'</option>').trigger('change');
					}
					else{
						console.log('2');
						$("#edit-location-"+splitData[2]).append('<option value='+ value.id +'>'+ value.name +'</option>').trigger('change');
					}
					$("#edit-location-"+splitData[2]).multiSelect('refresh'); // init the select
				});
				// $("#edit-location-"+splitData[2]).multiSelect('refresh'); // init the select
			}
		});
	}
});
0 likes
1 reply
vandan's avatar
Level 13

anyone suggestion for this issue ?

Please or to participate in this conversation.