Datetime picker click event

Datetime picker click event

cgozelecgozele Posts: 3Questions: 1Answers: 0

Hello,
I'm trying to write a click event function for a datetime picker. It will fetch data based on the selected date. So I am returning data with ajax. But this process only happens once and when I click it the second time, the function does not work.

t = new DateTime(document.getElementById('Takvim'), {
i18n: {
months: ['Ocak', 'Şubat', 'Mart', 'Nisan', 'Mayıs', 'Haziran', 'Temmuz', 'Ağustos', 'Eylül', 'Ekim', 'Kasım', 'Aralık'],
weekdays: ['Pz', 'Pzt', 'Sa', 'Ça', 'Pe', 'Cu', 'Cmt'],
}
});

    $(".dt-datetime-button").on('click', function(e) {

        var day = e.delegateTarget.dataset.day;
        var month = e.delegateTarget.dataset.month;
        var year = e.delegateTarget.dataset.year;
        var url = '@Url.Content("~/")' + 'Food' + '/GetFood';
        $.ajax({

            type: "POST",
            url: url,
            dataType: 'html',
            data: { "day": day, "month": month, "year": year },
            cache: false,
            success: function(states) {
                $("#inf").html(states);
            },
            error: function(ex) {
                alert('Failed to retrieve states.' + ex);
            }
        });
    });

Replies

  • kthorngrenkthorngren Posts: 21,299Questions: 26Answers: 4,945

    You might need to re-establish the click event each time the Datetime picker element is shown. Something like this:

      $('#Takvim').on('click', function () {
        $(".dt-datetime-button").on('click', function(e) { 
    
        });
      });
    

    If this doesn't help then please provide details of what is not working. Better is a link to your page or a test case replicating the issue so we can help debug.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

Sign In or Register to comment.