Nadiya
Nadiya

Reputation: 1527

Bootstrap Datetimepicker on select event

How do I access a js function exampleFunction() when date is selected? I want to pass the date value there.

text_field_tag for datetimepicker (haml):

= text_field_tag 'start_day', class: 'datepick'

Javascript:

$(".datepick").datetimepicker({
  timepicker: false,
  format: 'd/m/Y',
  closeOnDateSelect: true
});

Upvotes: 2

Views: 29176

Answers (4)

ShirleyCC
ShirleyCC

Reputation: 805

Simply:

$(".datepick").datetimepicker({
  format: 'd/m/Y',
}).on('select', function (e) {
        console.log('on select event');
    });

Upvotes: 0

Akshay Jindal
Akshay Jindal

Reputation: 385

You can achieve this by using below given code:

$("#datetimepicker6").on("dp.change", function (e) {
     console.log(e.date);
});

I your case, it should be :

$(".datepick").on("dp.change",function(e){ exampleFunction(e.date)  });

Remember this will call the example function on change in value of each datetimepicker, since you used class.

Reference URL: https://eonasdan.github.io/bootstrap-datetimepicker/

Upvotes: 10

Shivani P
Shivani P

Reputation: 416

Try this :

$(".datepick").datetimepicker({
  timepicker: false,
  format: 'd/m/Y',
  closeOnDateSelect: true
}).on('dp.change', function (ev) {
    exampleFunction() ;//your function call
});

Upvotes: 0

M. Junaid Salaat
M. Junaid Salaat

Reputation: 3783

If this is the plugin you are using then it would be Like this.

$(".datepick").datetimepicker({
  onChangeDateTime:exampleFunction
});
function exampleFunction(){
  console.log("Date Selected")
}

For full option list Reference: http://xdsoft.net/jqplugins/datetimepicker/

Hope it helps.

Upvotes: 2

Related Questions