Install of SELECT2


#1

Need a little help.

I copied these lines into the head as described

<link href=“https://cdn.jsdelivr.net/npm/[email protected]/dist/css/select2.min.css” rel=“stylesheet” /> <script src=“https://cdn.jsdelivr.net/npm/[email protected]/dist/js/select2.min.js”></script>

(forgive the editors bolluxing of the content please)

Copied this into the html

<select class=“js-example-basic-multiple” name=“states[]” multiple=“multiple”> <option value=“AL”>Alabama</option> … <option value=“WY”>Wyoming</option> </select>

and this into

$(document).ready(function() {
$(’.js-example-basic-multiple’).select2();
});

but the result is a box with the values in it and not the appearance shown on the “Basic Usage” page. What have I done wrong?

Thank you,
Chris


#2

It works fine when in a stand alone page, is it possible the class is found in another package somehow? Is there a way I can make the select unique so it doesn’t read from another class file?


#3

Looks like this image


#4

Rather than this


#5

Uncaught TypeError: $(…).select2 is not a function
at HTMLDocument.


#6

Hello? Posted a couple days ago and still seeking help


#7

Did you also install jQuery? It’s a prerequisite for Select2, and its <script> tag must appear before the Select2 <script> tag.


#8

Yes, jquery is loaded and working with other jquery functionality. You can see the results of the test at view-source:http://my.memoreebook.com/test6.php.


#9

Hello again, jusr wondering if anyone has any ideas.


#10

The same problem.

But the example is not the same text as in the html (there are no Timezone in bold).
Is there somewhere an instruction “how it should be in html, to be as in the example”


#12

Found it.
That’s better for all who started to learn.
https://codepen.io/SitePoint/pen/bELxVw


it’s ok


#13

This appears to have nothing to do with my original question.


#14

OK, I see that you’ve loaded jQuery and Select2, but your HTML (at test6.php) doesn’t contain a <select> element, nor does your JavaScript try to initialize a Select2 widget (either from a hard-coded <select> element in your HTML or via AJAX). Was the test6.php page meant to be a working example of your application? If not, please point me to an actual working page (one that at least includes the <select> element).


#15

That was just a page to display jquery is loaded. the actual page is huge. I assumed the problem was with the css but I commented it all out and still see the same issue. I then moved all the css into the test page “http://my.memoreebook.com/test5.php” and it still works fine. There’s something in the page I’m trying to use this in that’s causing a problem. Any thoughts on what might cause a conflict?

P.S. Thanks for the help!


#16

Sorry, but without seeing your actual code I don’t have any way of guessing what the problem might be.

The error message you originally posted occurs when you try to use Select2 without having loaded jQuery. Are you still getting that same error message?


#17

If I get an answer to my other question about single select I’ll work the code back in and if it’s still not working I’ll definitely post the code here.