Problems with jquery change events

Asked 2 years ago, Updated 2 years ago, 49 views

Previously, I wrote a post that asked questions as a beforeunload event when I left the page during the registration, exceptions I'm asking you again because there's a situation.

$("#form").on("change",function(e){
    if($(e.target).val().length > 0) {
        $(window).on("beforeunload", function (){
            If you leave the "return" page, the contents you are creating will not be saved.";            
        });
    } } else {
        $(window).off("beforeunload");
    }
});

I organized the code in this way, but the input or select inside the form works well with change, but the part that uses the datepicker inside does not seem to be recognized as a change event because it has a value of $("#datepicker"). Is there an event that recognizes the part that gives a value with jquery as change or operates whenever the val().length of that value is > 0 or higher?

jquery

2022-09-22 19:56

1 Answers

Pull trigger when certain events (such as when the date picker window is closed) are executed in that datepicker.

// Conceptual similar code. I didn't test it.
$('#datepicker input').on('focus', function () {
    $('#form').trigger('change');
});


2022-09-22 19:56

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.