Skip to content
  • Github
  • Facebook
  • twitter
  • About Us
  • Contact Us
  • Privacy Policy
  • Terms & Conditions
  • Site Map

XpertPhp

Expertphp Is The Best Tutorial For Beginners

  • Home
  • Javascript
    • Jquery
    • React JS
    • Angularjs
    • Angular
    • Nodejs
  • Codeigniter
  • Laravel
  • Contact Us
  • About Us
  • Live Demos
Bootstrap Multiselect Dropdown With Checkbox Using Jquery In Php

Bootstrap Multiselect Dropdown With Checkbox Using Jquery In Php

Posted on February 11, 2022December 11, 2022 By XpertPhp

In this tutorial, we will explain to you how to create bootstrap multiselect dropdown with checkbox using jquery In Php. Sometimes we need to select multiple options in the dropdown list with checkbox to search items.

In this example, We use the bootstrap multiselect plugin for create multiple dropdown with checkbox using Bootstrap, jQuery and PHP.
Multiselect Dropdown With Checkbox

Include Bootstrap and jQuery CDN Files

In this step, We need to include the bootstrap CDN and jquery CDN in our PHP file.

1
2
3
4
5
6
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-3-typeahead/4.0.2/bootstrap3-typeahead.min.js"></script>  
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-multiselect/0.9.13/js/bootstrap-multiselect.js"></script>
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-multiselect/0.9.13/css/bootstrap-multiselect.css" />

Create Multiselect Dropdown with Checkbox

Now, we will create the jquery multiselect dropdown using bootstrap. so you can see our full example code file.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
  <div class="container">
   <h2 align="center">Multiselect Dropdown With Checkbox In Php</h2>
   <form method="post" id="cars_form" name="cars_form">
    <div class="col-md-3">
    </div>
<div class="col-md-7">
<div class="form-group">
<label>Select Cars:</label><br/>
<?php
$cars = array (
  array("id"=>1,"name"=>"Volvo"),
  array("id"=>2,"name"=>"BMW"),
  array("id"=>3,"name"=>"Saab"),
  array("id"=>4,"name"=>"Land Rover"),
  array("id"=>5,"name"=>"Skoda"),
  array("id"=>6,"name"=>"Rolls Royce"),
  array("id"=>7,"name"=>"Audi")
);
?>
<select id="cars" name="cars[]" multiple class="form-control" >
<?php foreach($cars as $val){?>
<option value="<?php echo $val['id'];?>"><?php echo $val['name'];?></option>
<?php } ?>
</select>
</div>
<div class="form-group">
<input type="submit" class="btn btn-info" name="submit" value="Submit" />
</div>
</div>
   </form>
  </div>

Implement Multiselect Dropdown Checkbox

Now we will implement multiselect dropdown checkbox using jquery. so you can see the below example.

1
2
3
4
5
6
$('#cars').multiselect({
  nonSelectedText: 'Select Cars',
  enableFiltering: true,
  enableCaseInsensitiveFiltering: true,
  buttonWidth:'400px'
});

index.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<!DOCTYPE html>
<html>
<head>
  <title>Multiselect Dropdown With Checkbox In Php - XpertPhp</title>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-3-typeahead/4.0.2/bootstrap3-typeahead.min.js"></script>  
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-multiselect/0.9.13/js/bootstrap-multiselect.js"></script>
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-multiselect/0.9.13/css/bootstrap-multiselect.css" />
</head>
<body>
  <div class="container">
   <h2 align="center">Multiselect Dropdown With Checkbox In Php</h2>
   <form method="post" id="cars_form" name="cars_form">
    <div class="col-md-3">
    </div>
<div class="col-md-7">
<div class="form-group">
<label>Select Cars:</label><br/>
<?php
$cars = array (
  array("id"=>1,"name"=>"Volvo"),
  array("id"=>2,"name"=>"BMW"),
  array("id"=>3,"name"=>"Saab"),
  array("id"=>4,"name"=>"Land Rover"),
  array("id"=>5,"name"=>"Skoda"),
  array("id"=>6,"name"=>"Rolls Royce"),
  array("id"=>7,"name"=>"Audi")
);
?>
<select id="cars" name="cars[]" multiple class="form-control" >
<?php foreach($cars as $val){?>
<option value="<?php echo $val['id'];?>"><?php echo $val['name'];?></option>
<?php } ?>
</select>
</div>
<div class="form-group">
<input type="submit" class="btn btn-info" name="submit" value="Submit" />
</div>
</div>
   </form>
   <br />
  </div>
</body>
</html>
 
<script>
$(document).ready(function(){
$('#cars').multiselect({
  nonSelectedText: 'Select Cars',
  enableFiltering: true,
  enableCaseInsensitiveFiltering: true,
  buttonWidth:'400px'
});
$('#cars_form').on('submit', function(event){
  event.preventDefault();
  var form_data = $(this).serialize();
  $.ajax({
   url:"insert.php",
   method:"POST",
   data:form_data,
   success:function(data)
   {
    $('#cars option:selected').each(function(){
     $(this).prop('selected', false);
    });
    $('#cars').multiselect('refresh');
    alert(data);
   }
  });
});
});
</script>

Get Selected Values on Form Submit

Now finally When the user submits the form then data will be inserted into the database.
insert.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<?php
$connect = mysqli_connect("localhost", "root", "", "testdb");
 
if(isset($_POST["cars"]))
{
if(count($_POST["cars"])>1){
$cars = implode(",",$_POST["cars"]);
}else{
$cars = $_POST["cars"][0];
}
$query = "INSERT INTO cars(car_id) VALUES('".$cars."')";
if(mysqli_query($connect, $query))
{
  echo 'Data Inserted';
}
}
else{
echo "Please Choose any cars";
}
?>

Download

Php, Bootstrap

Post navigation

Previous Post: Laravel 9 CRUD Operation With Ajax Example
Next Post: Laravel 9 Send Email Example Tutorial

Latest Posts

  • Laravel 12 Ajax CRUD Example
  • Laravel 12 CRUD Example Tutorial
  • How to Create Dummy Data in Laravel 11
  • Laravel 11 Yajra Datatables Example
  • Laravel 11 Ajax CRUD Example
  • Laravel 11 CRUD Example Tutorial
  • Angular 15 CRUD Application Example Tutorial
  • Laravel 10 Form Validation Example Tutorial
  • Angular 15 Custom Form Validation Example
  • Laravel 10 Send Email Example Tutorial

Tools

  • Compound Interest Calculator
  • Hex to RGB Color Converter
  • Pinterest Video Downloader
  • Birthday Calculator
  • Convert JSON to PHP Array Online
  • JavaScript Minifier
  • CSS Beautifier
  • CSS Minifier
  • JSON Beautifier
  • JSON Minifier

Categories

  • Ajax
  • Angular
  • Angularjs
  • Bootstrap
  • Codeigniter
  • Css
  • Htaccess
  • Interview
  • Javascript
  • Jquery
  • Laravel
  • MongoDB
  • MySql
  • Nodejs
  • Php
  • React JS
  • Shopify Api
  • Ubuntu

Tags

angular 10 tutorial angular 11 ci tutorial codeigniter 4 image upload Codeigniter 4 Tutorial codeigniter tutorial CodeIgniter tutorial for beginners codeigniter with mysql crud operation eloquent relationships file upload File Validation form validation Image Upload jQuery Ajax Form Handling jquery tutorial laravel 6 Laravel 6 Eloquent Laravel 6 Model laravel 6 relationship laravel 6 relationship eloquent Laravel 6 Routing laravel 7 Laravel 7 Eloquent laravel 7 routing laravel 7 tutorial Laravel 8 laravel 8 example laravel 8 tutorial laravel 9 example laravel 9 tutorial Laravel Framework laravel from scratch laravel social login learn jquery nodejs pagination payment gateway php with mysql react js example react js tutorial send mail validation wysiwyg editor wysiwyg html editor

Copyright © 2018 - 2025,

All Rights Reserved Powered by XpertPhp.com