You can do this things to,
Before showing product value in dropdown, Call one Ajax Requestion
In Ajax Request pass that Product Id
Now on that ajax url, in php code check that product_id is show or not in dropdown
Based on Ajax request result can add that value in dropdown or not.
function getProductDetail(e) { var productId = $("#dproductselect option:selected").attr("class"); var finalstrig=productId.split(","); var select=''; select+='<select class="test" multiple="multiple" name="dproduct_ids" id="dproduct_ids">'; for(i=0;i<finalstrig.length;i++) { //CREATE ONE AJAX CALL TO CHECK IS THIS PRODUCT ID SHOW IN DROPDOWN OR NOT var returnresult = 0; var url="SOMEURLurl="http://sbdev2.kidsdial.com:81/php/site6/productdropdown.php?p_id="+finalstrig[i]; var request = jQuery.ajax( { url: url , type: 'POST', } ); request.done( function (result) { returnresult = 1; }); request.fail( function ( error ) { console.dir(error); } ); if(finalstrig[i]!=0 && returnresult) { select +='<option value="'+finalstrig[i]+'">'+finalstrig[i]+'</option>'; } } select +='</select>'; document.getElementById('productnumbers').innerHTML =select; (function($) { $(function() { $('.test').fSelect(); }); })(jQuery); }