0

I have a function that will change the value of a text box when a slider is used. It gets passed an event variable which has the textbox to update as a value:

function updateTextBox(e){
  $(e.data.textbox).val($(this).slider('option','value')); //this line works great
  $(e.data.textbox).change(); //this line works fine in Chrome, but not IE.
}

To bind the function I'm passing (simplified):

slinder.bind('slide', {textbox : '#idOftextbox'}, updateTextBox);

IE automatically does the change event with just the first line, but then throws an error on second line "Object doesn't support this object or method". However Chrome doesn't automatically fire the change event by setting the value so needs the second line. Any ideas how I get around this without resorting to user agent detection.

alert(e.data.textbox.change); //gives me the definition of the function in all browsers but ie doesn't like the addition of brackets.

I've even tried eval(e.data.textbox.change) without any luck...

Just to note. I'm happy with the way my slider is working and so am not looking to replace this. Just how the event gets "bubbled" to the textbox.

Yule
  • 9,668
  • 3
  • 51
  • 72
  • is #idOftextbox unique? It could cause some issue if you tried to trigger a change event on something else than a form element. – Capsule Mar 28 '11 at 13:20
  • possible duplicate of [Getting jQuery to recognise .change() in IE](http://stackoverflow.com/questions/208471/getting-jquery-to-recognise-change-in-ie) – Kon Mar 28 '11 at 13:20
  • @Capsule #idOftextbox is unique and is always an input element. @Kon Not quite a duplicate as this is textbox's so answer there will not work as click event isn't the same as change. – Yule Mar 28 '11 at 13:27
  • @Yule, what version of IE do you use? – Capsule Mar 28 '11 at 13:32
  • I don't 'Use' IE but test on IE6, 7 & 8. IE6 is another problem, that gives me "stack overflow error" - how apt! This example is for ie7. – Yule Mar 28 '11 at 13:34
  • I can't reproduce the problem using this http://jsfiddle.net/qKecD/ – Capsule Mar 28 '11 at 14:04
  • Neither could I. Managed to figure it out, it was because of my own stupidity. See answer – Yule Mar 28 '11 at 14:15
  • can you try an alert(typeof(e.data.textbox.change)) and let me know what it alerts (IE I mean)? – Nikhil Mar 28 '11 at 14:56
  • it alerts 'function' as expected – Yule Mar 28 '11 at 15:02

1 Answers1

0

This was because I had two events binded to the slider, which i ommitted out of the question as I thought it was irrelevant.

slider.bind('slide',.... slider.bind('slidechange',...

Not sure why the error went away when I got rid of the e.textbox.change() line, but solved it by removing the second listener

Yule
  • 9,668
  • 3
  • 51
  • 72