Using jquery date-time picker

It's very easy to use jquery date-timer picker in webpages. Here is a very simple way on how to do this. I'm going to create a html file that will demonstrate this

so, first of all, create a html file and give it a name. In the header section of the html file, add the following link

<link rel="stylesheet" href="jquery-ui-1.8.6.custom.css" type="text/css">

Download this css file from here and put it in the current directory.

Create a folder in the current directory and give it name 'images'. Download this file and put it in the images folder.

Now, add the following css code in the header

<style type="text/css">
.ui-timepicker-div .ui-widget-header{ margin-bottom: 8px; }
.ui-timepicker-div dl{ text-align: left; }
.ui-timepicker-div dl dt{ height: 25px; }
.ui-timepicker-div dl dd{ margin: -25px 0 10px 65px; }
.ui-timepicker-div td { font-size: 90%; }
</style>


Now, download these three files from here and put them in the current directory
jquery-1.4.4.min.js
jquery-ui-1.8.6.custom.min.js
jquery-ui-timepicker-addon.js

Now, we have to add these file in the html file. To do this, we have to write the following code in the header section.

<script type="text/javascript" src="jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="jquery-ui-1.8.6.custom.min.js"></script>
<script type="text/javascript" src="jquery-ui-timepicker-addon.js"></script>


Our header section is finished. close it with </head> tag

In the body section we have to create input fields and call javascript function to use the date-time picker. We can use only datepicker, only timepicker or both. Below is a simple code that shows how to do this

<input name="example1" id="example1" value="" type="text">
<script type="text/javascript">
$('#example1').datepicker({
minDate: new Date(),
dateFormat:'dd/mm/yy'
});
</script>


<input id="example2" name="example2" type="text">
<script type="text/javascript">
$('#example2').timepicker({
hourGrid: 4,
minuteGrid: 10,
ampm:true
});
</script>


<input id="example3" name="example2" type="text">
<script type="text/javascript">
$('#example3').datetimepicker();
</script>

This is very basic demonstration. We can do customize them. To see the various options that can be used visit here

Now, click on the input field. It should work!

Comments

Popular posts from this blog

Run tasks in background in Spring

Conditional field inclusion in Jackson and Spring Boot

How to configure Wildfly 10 to use MySQL