Uncaught TypeError: $(...).select2 is not a function and how to use the select2 dropdown box.
Here is a simple solution.
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/css/select2.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.8/js/select2.min.js" defer></script>
<script>
$(document).ready(function(){
$("#district_name").select2({
allowClear: true
});
});
</script>
</head>
<body>
<select name="district_name[]" id="district_name" multiple="" class="form-control">
<option value="0">For All</option>
<?php
$sql_user=mysqli_query($connc,"select * from district_association order by district_name");
while($res=mysqli_fetch_array($sql_user))
{
$disid=$res['id'];
$district_name=$res['district_name'];
?>
<option value="<?php echo $disid; ?>"> <?php echo $district_name; ?> </option>
<?php
}
?>
</select>
</body>
</html>
Get the latest news and updates by signing up to our daily newsletter.We won't sell your email or spam you !