0

I am using below JS code to hide/remove duplicate values from a lookup column.

<script language="javascript" type="text/javascript" 
src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<script type="text/javascript">
var previousOption;

$(document).ready(function() {
$('#Vendor_x0020_name').parent().next().find('select option').each(function() {
    if (this.text == previousOption) $(this).remove();
    previousOption= this.text;
});
});
</script>

The lookup column name is: Vendor Name and it has some duplicate values showing up in the drop-down. The same code works when added on the New item form in SPOnline list but doesn't work when added to new item form of SharePoint server 2013 list.

Can someone help,thanks.

1

2 Answers 2

0

This works for me:

<script language="javascript" type="text/javascript" 
src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<script type="text/javascript">
var previousOption;

$(document).ready(function() {
$("td[id^='Vendor_x0020_name']").parent().next().find('select option').each(function() {
    if (this.text == previousOption) $(this).remove();
    previousOption= this.text;
});
});
</script>
0

We can use the code below to achieve it.

<script type="text/javascript" src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<script type="text/javascript">
var previousOptions={};
$(function() {
    $("select[title='Vendor Name'] option").each(function() {
        if (previousOptions[this.text]){
            $(this).remove();
        }else {
            previousOptions[this.text] = this.value;
        }        
    });
});
</script>

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.