1

My form contains 5 drop-down lists. I'm using JQuery Select2 for each drop-down list. When I'm trying to edit it only one drop-down list shows previous set value.

My code:

$('.select2').select2({
  //placeholder: 'Select an option'
});

if (data.candidateId !== '') {
  $("#candidateParentId").select2().select2(data.candidateParentId, data.parent);
  $("#candidateTypeId").select2().select2(data.candidateTypeId, data.candidateType);
}

But this code shows only Candidate Parent Value and not Candidate Type value.

I'm getting both values in console.

I just refer to this: How to set selected value of jquery select2?

Any kind of help is appreciated. Thanks in advance.

3
  • Check this link. link Commented Mar 15, 2019 at 14:09
  • This link shows only for single drop-down list, need more than one drop-down on the same form. Commented Mar 16, 2019 at 4:53
  • $("#candidateParentId").select2().select2('val', data.candidateParentId); $("#candidateTypeId").select2().select2('val',data.candidateTypeId); Here you can try this. data.candidateParentId or data.candidateTypeId values are present in your dropdowns Commented Mar 16, 2019 at 19:33

1 Answer 1

0

Try this

$("#candidateParentId").select2("val", data.parent);

$("#candidateTypeId").select2("val", data.candidateType);
Sign up to request clarification or add additional context in comments.

1 Comment

Welcome to Stack Overflow! please format your code and add more details to the answer for other developers to understand what exactly you're trying to explain.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.