Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Think of this scenario,
If I add two user entries to people picker(multiple selection is permitted) field.
I need to count these entries using java script/Jquery(Output what i want is: 2).
how can I do this.
I tried to get the value of that field using Jquery it's giving hell out of things.
This is what i tried:

 $("#DivId").focusout(function () {
            alert($("#DivId").html());
        });
share|improve this question

2 Answers 2

Update: The people picker will create a span element for each user, you should be able to use this code (using jQuery):

$('.ms-entity-resolved').length

If you have several pickers you should be able to split them, for example by [name*=UserFieldValue] like this:

$('[name*=UserFieldValue]').each(function(){
  var count = $(this).next().find('.ms-entity-resolved').length;
  console.log(count);
});
share|improve this answer
    
Thank You @eirikb .. I am using 2010 version.. I will check this code –  Praveen M P Feb 24 at 7:03

EntityEditor.js contains method GetPickerControlValue for getting picker control value(s). (by default ';' delimiter is used for multiple values)

The following code demonstrates how to get the number of control values in Picker Control:

var pickerControlVals = GetPickerControlValue(currentEntityEditorContextId, true, true);

var numOfUsers = pickerControlVals.split(';').length - 1;
console.log(numOfUsers);

Variable currentEntityEditorContextId corresponds to Picker Control Id and available on the page where Picker Control is rendered

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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