Datepicker in JavaScript code with Example – Lightpick

Datepicker in JavaScript code with Example - Lightpick
Code Snippet:Lightpick
Author: Rinat G
Published: January 19, 2024
Last Updated: January 22, 2024
Downloads: 11,091
License: MIT
Edit Code online: View on CodePen
Read More

Yet another datepicker in JavaScript code with example and using guide. The Lightpick is a pure JavaScript datepicker plugin to pick single, multiple and ranged date. It creates a beautiful calendar widget near the input field to add/pick selected date.

How to Use Lightpick javascript Datepicker

1. To get started with Lightpick datepicker, you need to load Bootstrap CSS and moment.js into the head of your HTML document.

<!-- Bootstrap JS -->
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>

<!-- Moment Js -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.min.js"></script>

2. After that, include the lightpick CSS and JavaScript file into your webpage.

<!-- Lightpick CSS -->
<link rel="stylesheet" href="css/lightpick.css"> 

<!-- Lightpick JS -->
<script src="js/lightpick.js"></script>

2.1 You can also load lightpick by CDN link.

<script src="https://unpkg.com/lightpick@latest/lightpick.js"></script>

3. Create input element with the following mentioned attributes.

<input type="text" id="myDatepicker" class="form-control form-control-sm"/>

4. Finally, initialize the plugin with the following script.

<script>
new Lightpick({
    field: document.getElementById('myDatepicker'),
    onSelect: function(date){
        document.getElementById('result-1').innerHTML = date.format('Do MMMM YYYY');
    }
});
</script>

This awesome JavaScript plugin is developed by Rinat G. Please check the demo page or official repository for more advanced usage.

1 thought on “Datepicker in JavaScript code with Example – Lightpick”

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

About CodeHim

Free Web Design Code & Scripts - CodeHim is one of the BEST developer websites that provide web designers and developers with a simple way to preview and download a variety of free code & scripts. All codes published on CodeHim are open source, distributed under OSD-compliant license which grants all the rights to use, study, change and share the software in modified and unmodified form. Before publishing, we test and review each code snippet to avoid errors, but we cannot warrant the full correctness of all content. All trademarks, trade names, logos, and icons are the property of their respective owners... find out more...

Please Rel0ad/PressF5 this page if you can't click the download/preview link

X