Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the value of current selected date from calendar eonasdan

I am using http://eonasdan.github.io/bootstrap-datetimepicker/ for calendar. Now I want to pick the selected date by the user. I am stuck with this calendar. Please help me to get the current selected date by the user I have used js to get the value.

On each date there is a class named "day". Now I wanted to get the value of the attribute "data-day" which have the value of the date as follows:

$(".day").click(function(){
            var clicked = $(this).attr('id');
         alert(clicked);
         });

It returns the attribute's value only one time it's not recognizing the second click.

Please help me with js or this eonasdan plugin.

like image 622
Tausif Anwar Avatar asked Aug 26 '15 09:08

Tausif Anwar


2 Answers

HTML

<br/>
<!-- padding for jsfiddle -->
<div class="row">
    <div class="col-md-4 col-xs-6">
        <input type="text" class="form-control" id="datetimepicker2" />
        <br>
        <input type="button" class="btn btn-success" id="getDate" value="Get Date" />
    </div>
         <span id="SelectedDate"></span>
</div>

JS

$('#datetimepicker2').datetimepicker();

$('#getDate').click(function () {
    console.log($('#datetimepicker2').data('date'))
    $('#SelectedDate').text($('#datetimepicker2').data('date'))
})

DEMO
Get Only Date Part

like image 176
J Santosh Avatar answered Nov 07 '22 07:11

J Santosh


I have found methods for calendar described at linked page. So for example to see what have user entered you have to:

$('#datetimepicker').data("DateTimePicker").date()

input here your id and as result receive object which has '_d' field with value.

data('DateTimePicker')

also has a lot of taste functions to configure plugin.

like image 41
Illia Olenchenko Avatar answered Nov 07 '22 08:11

Illia Olenchenko