Friday, 26 Apr, 2024 -336

How to add Datepicker in Bootstrap

Datepicker requires an additional library in order to be included using Bootstrap. Either a property or a method can be used to initialize the textbox.When you click on the textbox, a popup box with a calendar appears.


1. Download and Include


  •  Download and Include.

  •  Also, need to download Bootstrap date picker which you can download from here.

  • Include jQuery, Bootstrap, and Bootstrap datepicker script and CSS files.

    


<!-- jQuery -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
<!-- Bootstrap -->
<link href='https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css' rel='stylesheet' type='text/css'>
<script src='https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.min.js' type='text/javascript'></script>
<!-- Datepicker -->
<link href='https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.9.0/css/bootstrap-datepicker.min.css' rel='stylesheet' type='text/css'>
<script src='https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.9.0/js/bootstrap-datepicker.min.js' type='text/javascript'></script>



2. Initialize

Create an input element and initialize it using either of two ways –


  •     data-provide="datepicker" attribute.

  •     datepicker() method



Example 


In the example, I am using both of the ways to add datepicker on the textboxes. On the first textbox initialize it using datepicker() and in the second textbox add it using attribute –  data-provide="datepicker".


<div class='container' style='margin-top: 100px;'>
    <input type='text' class="form-control" id='datepicker' style='width: 300px;' > <br>
    <input type='text' class="form-control" data-provide="datepicker" style='width: 300px;' >
</div>
 
<!-- Script -->
<script type="text/javascript">
$(document).ready(function(){
    $('#datepicker').datepicker();
});
</script>


Tags
Most Popular
img
How to install WordPress
02 Apr, 2024 view: 1889
img
Xampp Tutorial Create Your Own Local Test Server
02 Apr, 2024 view: 770
img
How to Install Laravel
02 Apr, 2024 view: 759
img
PHP is not recognized as an internal or external command
02 Apr, 2024 view: 558
img
How to Install Composer on Windows
01 Apr, 2024 view: 543
img
Summernote image upload
01 Nov, 2023 view: 496
img
How to clear select2 selected value in js
01 Nov, 2023 view: 377
img
Zipping and Unzipping Files in Linux
02 Apr, 2024 view: 343
img
How to add Datepicker in Bootstrap
26 Apr, 2024 view: 336
img
How to Import a MySQL Database using Command Line
02 Apr, 2024 view: 328
img
How to Installation Laragon
01 Apr, 2024 view: 179
img
How to Installing an SSL certificate on your server using cPanel
06 Apr, 2024 view: 147
img
Paypal Payment Gateway Integration With Laravel
06 Apr, 2024 view: 120
img
How to Use Laravel Middleware to Protect Your Application
09 Apr, 2024 view: 106
img
Laravel Cache Clear Command Php Artisan Optimize
09 Apr, 2024 view: 106
img
why important website development learn
10 Apr, 2024 view: 104
img
Laravel Authentication Tutorial
09 Apr, 2024 view: 103
img
How to Integrate Stripe Payment in Laravel
06 Apr, 2024 view: 101
img
laravel qr code generator package
18 Apr, 2024 view: 94
Trending