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
});
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.
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/
Try this :
$(".datepick").datetimepicker({
timepicker: false,
format: 'd/m/Y',
closeOnDateSelect: true
}).on('dp.change', function (ev) {
exampleFunction() ;//your function call
});
Simply:
$(".datepick").datetimepicker({
format: 'd/m/Y',
}).on('select', function (e) {
console.log('on select event');
});