How to change the color of a button when changing a date value, as well as when changing a text field value?

I have a view in which there are a number of text fields and a date picker with a gray button. When the textbox and datepicker value is changed, the button color turns red, and if I replace the new input value with a preview, it will turn gray again.

My code (below) works fine with a text box, but not with the datepicker parameter:

$(".class Selector").each(function(){
  $(this).on('change blur keyup',function(){
    if(oldvalue of textbox1!=newvalue of textbox1){
      $("#button id ").css('backgroundcolor','red')
    }
    else if(oldvalue of textbox2!=newvalue of textbox2){
      $("#button id ").css('backgroundcolor','red')
     }
    else if(oldvalue of datepicker !=newvalue of datepicker){
      $("#button id ").css('backgroundcolor','red')
     }
    else {
      $("#button id ").css('backgroundcolor','gray')
    }
  });
});

My code works with text field values, but it doesn't work in case of datepicker

In this case, it .onworks first when I want to change the selection date first. When I click on the date picker text box, I always get a new date undefined.

Any help please. Thank you

+4
1

JQuery UI datepicker. JQuery UI datepicker , name onSelect, . , .

0

Source: https://habr.com/ru/post/1568972/


All Articles