0

I have a simple input which loads initially its value from a webservice.

 <input id="inputDisponibilite" type="hidden" value="" data-match="infosBase.0.Disponibilite">

Here I have the attribute data-match which loads the value initially.

After that, I have a function which transfers the value of a slider into the value of my input.

slide: function (event, ui) {
       $(this).prev().attr('value',ui.value); 

//this makes changes of the value of my input and I shouldn't touch it.

I have another function which should detect the change of value in my first input and do some treatment, but it seems that this change is not seen, maybe because I am not writing directly into my input.

I have used : on('change , function () {} / change() / and bind() and also eventLisneter of jquery, but the problem persists.

My function :

$("#inputDisponibilite").on('change',function () {

      var DisponibiliteValue = $(this).attr("value") ;
 })

Is there any other way to catch the change?

mhatch
  • 4,441
  • 6
  • 36
  • 62
firasKoubaa
  • 6,439
  • 25
  • 79
  • 148
  • Possible duplicate: http://stackoverflow.com/questions/19325938/trigger-action-on-programmatic-change-to-an-input-value – mhatch Aug 25 '16 at 18:30

1 Answers1

0

Use prop(). attr() takes the initial value which is ""

$("#inputDisponibilite").on('change',function () {
  var DisponibiliteValue = $(this).prop("value") ;
})

Because of the inconsistent behaviour of attr(), prop() was introduced in jquery 1.6.

However, I have no idea why aren't you using val() to get the value which should work properly

var DisponibiliteValue = $(this).val() ;
bipen
  • 36,319
  • 9
  • 49
  • 62