3

I have a lookUp field named Contractor in my sharepoint list which is multi select box. I am trying to get the values of selected contractor names in SelectCandidate box. PFB my code:

var selectedContractors=[];
$("#Contractor_b9ee1d81-a7b7-45ec-bfc6-15c0f8fea99b_AddButton").click(function()
{
$("#Contractor_b9ee1d81-a7b7-45ec-bfc6-15c0f8fea99b_SelectResult :selected").each(function(i,selected)
{
selectedContractors.push($(selected).text());

});
alert(selectedContractors);
});

BUt its not working. any help?

Thanks, Dheeraj

2
  • 1
    Can you add the HTML code of your SELECT? – Juan Pablo Pussacq Laborde Jun 29 '17 at 12:00
  • That is actually a look up field with option to select multiple values – Dheeraj Jun 29 '17 at 12:23
5

Try this:

var selectedContractors=[];
$("#Contractor_b9ee1d81-a7b7-45ec-bfc6-15c0f8fea99b_AddButton").click(function()
{
$("#Contractor_b9ee1d81-a7b7-45ec-bfc6-15c0f8fea99b_SelectResult option").each(function()
{
selectedContractors.push($(this).val());

});
alert(selectedContractors);
4

Please refer below code. This works perfectly (In below code I have changed my ID value to the same ID value as yours):

$("#Contractor_b9ee1d81-a7b7-45ec-bfc6-15c0f8fea99b_SelectResult option").each(function(){
    alert($(this).val());
});

Note:

Multiselect lookup renders as following(refer below image).enter image description hereenter image description here

Here we have two sections :

  1. multiselect possible values

  2. multiselect selected values

All the options under 2. multiselect selected values are selected options. So you can directly get all the options from this sections as these are all selected one.

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.