1

I have a requirement that seeks to remove a sharepoint dropdown option if selected and when you click the save button the option selected needs to get removed from the dropdown menu.

here's my jquery code:

$(document).ready(function(){

removeItems();

});

function removeItems() {

$("#ctl00_m_g_080195fc_7520_4906_a7d3_7f90b10d5b73_ctl00_toolBarTbl_RightRptControls_SaveButton2_ctl00_diidIOSaveItem").click(function(){

var selectedItem = $("#ctl00_m_g_080195fc_7520_4906_a7d3_7f90b10d5b73_ctl00_CustomFieldIterator1_ctl02_ctl00_ctl00_ctl04_ctl00_DropDownChoice option:selected").val();
alert(selectedItem+" is removed from the dropdown options.");
  $("#ctl00_m_g_080195fc_7520_4906_a7d3_7f90b10d5b73_ctl00_CustomFieldIterator1_ctl02_ctl00_ctl00_ctl04_ctl00_DropDownChoice option:selected").remove();

});

}

this seems to work when saving the form but when I load the form again the option loads again. Anyone with help??

0
 $("#ctl00_m_g_080195fc_7520_4906_a7d3_7f90b10d5b73_ctl00_CustomFieldIterator1_ctl02_ctl00_ctl00_ctl04_ctl00_DropDownChoice option:selected").remove();

Above line will only remove data from loaded DOM (Client browser).

To remove from SharePoint dropdown value,

var categoryField = cldList.get_fields().getByInternalNameOrTitle("Category");
var categoryChoiceField = context.castTo(categoryField, SP.FieldChoice);
context.load(categoryChoiceField);

context.executeQueryAsync(function () {
        var categoryChoices = categoryChoiceField.get_choices();

          //now your logic
          //var i=categoryChoices.indexOf(SelectedValue);
          //categoryChoices.splice(i, 1);
            categoryChoiceField.set_choices(categoryChoices);
            categoryChoiceField.updateAndPushChanges();
            context.executeQueryAsync(function () { }, function () { });

    }, function () { }); 
  • Hi Anil please provide a complete solution if you may, I'm not sure what to put in these functions that are parameters. I'm quite not new in SP – Vusi85 Jul 9 '18 at 13:56
  • I finally got it to work. Thank you very much @Anil Pal – Vusi85 Jul 10 '18 at 6:48
  • @Vusi85, Great. If above solution worked for you, mark it as answer. it could help others too. – Anil Pal Jul 10 '18 at 8:46

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.