MB34
MB34

Reputation: 4434

Select2-Not converting my select

I am trying to use the Select2 JQuery control and can't get it to work with a select on my form.

This select is defined like this:

<select class="form-control" 
        name="QuestionBasicSection.Questions[3].ANSWER_LOOKUP_OPTION_ID" 
        id="QuestionBasicSection.Questions[3].ANSWER_LOOKUP_OPTION_ID" 
        multiple>
    <of course I have several options here>
</select>

<script>
    $(document).ready(function () {
        $("#QuestionBasicSection.Questions[3].ANSWER_LOOKUP_OPTION_ID").select2();
    });
</script>

But the select2 is not being converted nor showing and I can't determine why. Could it have something to do with the id of the <select>?

Upvotes: 0

Views: 124

Answers (1)

aprabaldi
aprabaldi

Reputation: 141

The problem is in the selector, #QuestionBasicSection.Questions[3].ANSWER_LOOKUP_OPTION_ID is not a valid selector due to the dots and brackets, you can scape those characters this way:

$("#QuestionBasicSection\\.Questions\\[3\\]\\.ANSWER_LOOKUP_OPTION_ID").select2();

Upvotes: 1

Related Questions