0

How to implement logic button "Remove" in JQuery to remove a value from dropdown (multivalue)?

enter image description here

1

I wrote a blog about this: https://derekgusoff.wordpress.com/2013/06/06/setting-multi-valued-lookups-in-forms-with-jquery/

Here's the function to remove the option. You might need to inspect to DOM to make sure the structure hasn't changed since 2013. Read the blog for more details:

//var selector = "[id$='MultiLookupPicker']"; //for 2010 or 2007
var selector = "[id$='MultiLookup']"; //for 2013


function removeChoice(text, columnName) {
    $("[title='" + columnName + " selected values'] option").each(function () {
        if ($(this).text() == text) {
            $(this).appendTo($("[title='" + columnName + " possible values']"));
            var multilookupPickerVal = $(selector).val();
            var valToRemove = $(this).val() + "|t" + $(this).text();
            var newValue = multilookupPickerVal.replace(valToRemove, "");

            $(selector).val(newValue);
        }
    });
}
0

This code is working:

$(document).ready(function () { 
    $("[id$='_SelectCandidate'] option[value='6']").remove();
    $("[id$='_SelectCandidate'] option[value='7']").remove();
    $("[id$='_SelectCandidate'] option[value='8']").remove();
    $("[id$='_SelectCandidate'] option[value='9']").remove();
    $("[id$='_SelectCandidate'] option[value='10']").remove();

    var $selOptions = "<OPTION title=Middle East value=6>Middle East</OPTION><OPTION title=North America value=7>North America</OPTION><OPTION title=Oceania value=8>Oceania</OPTION><OPTION title=South America value=9>South America</OPTION><OPTION title=The Caribbean value=10>The Caribbean</OPTION>";

    // this is the list of initial items (matching the ones above) that are used when the item is saved 

    var $resultSpOptions = "6|tMiddle East|7t|tNorth America|8t|tOceania|9t|tSouth America|t10|tThe Caribbean";

    $("[id$='_SelectResult']").append($selOptions);

    // append the new options to our hidden field (this sets the values into the list item when saving) 

    $("[id$='MultiLookup']").val($selOptions); 
    });

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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