0

I am using .change() function to check for changes inside an input and give an alert if a change occurred but I must be doing something wrong cause this isn't working :

jsFiddle

$(document).ready(function() {
    var sizes = ["0", "1", "2", "3", "4", "5", "5", "6", "7"];

$("#slider").slider({
      orientation: "vertical",
      range: "min",
      animation:false,
      min: 0,
      max: 8,
      value: 0,
  slide: function(event, ui) {
      $('.convert').val(sizes[ui.value]);      
  }
});

       $('.convert').change(function(e){
           alert("works?");
       });

       $('.convert').keypress(function(e){
           alert("works?");
       });

 });
Eduard Uta
  • 2,382
  • 3
  • 27
  • 35
Alin
  • 1,128
  • 3
  • 19
  • 44

3 Answers3

1

Enter text then focus out the event seems to fire, I think it doesn't fire change until you blur

Change the event to $('.convert').on('keyup', function(){ alert('foo');}); (Thanks to Chris B.)

See updated fiddle : http://jsfiddle.net/6ys3derm/2/

Zach Leighton
  • 1,909
  • 16
  • 22
  • Karl's pointed out my error...it's what I was looking for. +1 for the answer though. – Alin Dec 11 '14 at 16:52
1

Hmm. Can you try this?

$('document').on('change', '.convert', function(){
  alert("it works :-)");
});
  • Karl's pointed out my error...it's what I was looking for. +1 for the answer though. – Alin Dec 11 '14 at 16:51
1

the slider has its own change event

fiddle

$(document).ready(function() {
    var sizes = ["0", "1", "2", "3", "4", "5", "5", "6", "7"];

  $("#slider").slider({
        orientation: "vertical",
        range: "min",
        animation:false,
        min: 0,
        max: 8,
        value: 0,
    slide: function(event, ui) {
        $('.convert').val(sizes[ui.value]);      
    },
      change:function(){                     //called onchange
          alert("slider changed");  
      }
  });

});
andrew
  • 8,963
  • 7
  • 27
  • 58
  • Karl's pointed out my error...it's what I was looking for. +1 for the answer though. – Alin Dec 11 '14 at 16:53