Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

How to use Bootstrap Datepicker to get date on change event ?

  • Last Updated : 30 Nov, 2021

In this article, we will learn how to use Bootstrap Datepicker to get a date on changes of events. Bootstrap Datepicker is an open-source repository that provides an API to integrate date time picker into the frontend of the website. One should have a basic knowledge of HTML, CSS, jQuery, and Bootstrap.


  • Create an HTML file.
  • Please follow the below code format to link some external CSS to your code inside the head tag by following this order.
  • Start by including the bootstrap CSS  in your file. Add the bootstrap datepicker CSS to your file. Finally, you need to add the font awesome CSS to your HTML file.

<link rel=”stylesheet” href=”” />
<link rel=”stylesheet” href=”” />
<link rel=”stylesheet” href=”” />   

  • Following the below code format, attach some external JavaScript files to your code inside the head tag by following this order.
  • Start by including the jquery JavaScript in your file. The second step is to add the bootstrap JavaScript to your file. Finally, you need to add the bootstrap datetimepicker JavaScript to your HTML file.

<script src=””> </script>
<script src= “”></script>
<script src=””></script>

  • Add a class name as “datepicker” and other bootstrap classes to an input field as required
  • You can use any icon from any resource like font awesome or any other platform to beautify your input field by aligning the icon in line with the input field.
  • It is then necessary to initialize the date picker to the input field so that when the user clicks that input field, the pop-up calendar will appear and they can then pick the date from that prompt.

Example: In this example, we take an input field with class name as “datepicker”, and initialize the datepicker on this input using datepicker()

A calendar appears when the user clicks the input field, and a date can be selected from the calendar. As soon as the user selects a date from the calendar, it is automatically written into the input field. We add an event listener onchange for that input field. When a selection is made in that input field, the onchange() callback method is automatically called to get the value of the input field using the jQuery val() method.  


<!DOCTYPE html>
    <link rel="stylesheet"
    <link rel="stylesheet" 
    <link rel="stylesheet" 
    <script src=
    <script src=
    <script src=
        .container {
            display: flex;
            justify-content: center;
            margin-top: 30px;
        container {
            color: green;
    <h1 class="container">
    <div class="container">
        <div class="datepicker date 
                    input-group p-0 shadow-sm">
            <input id="reservationDate" 
                   placeholder="Choose a date" 
                   class="form-control py-4 px-4" />
            <div class="input-group-append"
              <span class="input-group-text px-4">
                  <i class="fa fa-clock-o"></i>
    <div class="container">
        <p id="showdate"> No Date is Picked </p>
            clearBtn: true,
            format: "dd/mm/yyyy",
        $(".datepicker").on("change", function() {
            let pickedDate = $("input").val();
            `You picked this ${pickedDate} Date`);


Attention reader! Don’t stop learning now. Get hold of all the important HTML concepts with the Web Design for Beginners | HTML  course.

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!