I’m having some IE8 javascript issues (joy).
Basically, I’m needing to convert any negative number entries in a certain textbox to a positive value. I figure I would do it like this:
$('input[type="text"]').live('change', function () {
var number = $(this).val();
if (number < 0)
{
$(this).val(-number);
}
});
Later on I do stuff when the textbox’s focus is lost:
$('input[type="text"]').live('blur', function () {
// do stuff with textbox's _positive_ number
})
Unfortunately with IE8 when the value of the textbox is changed (ie. you enter -23 in the textbox), the change event is fired twice and the blur event is not fired at all.
Other modern browsers don’t do this.
- Why is the change event fired twice?
- Why is the blur event not firing?
- How do I fix it?
Go here to see this happening: http://jsfiddle.net/ajbeaven/AwZKM/
When you set the
valueproperty of a form element to a different value, thechangeevent fires in IE8 so this linetriggers the change event again. The other problem you are having with the blur event not firing, if i change the code to
It works, which makes me think something is going on when the change and blur event’s are bound with
.live. Sorry i know not much of a solution, maybe someone can come up with some ideas after reading this.