Ticket #10132 (closed bug: fixed)
.val(...) in change handler invokes change handler in IE
| Reported by: | davidwebster48@… | Owned by: | dmethvin |
|---|---|---|---|
| Priority: | low | Milestone: | None |
| Component: | event | Version: | 1.6.2 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
When you have a function bound the the change event of an input field, and the function changes the input field's value using .val(...), the change event handler gets invoked twice (once from the real change, and once from calling .val(...)). This happens in IE8 and IE9, but not in FireFox 6 or Chrome.
The expected output from the code below is that "change" will be logged once, however it actually gets logged twice in IE.
<!doctype html>
<html>
<head>
<title>x</title>
</head>
<body>
<input type="text" id="inputField" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script>
$("#inputField").change(function() {
console.log("change");
$(this).val("newval");
});
</script>
</body>
</html>
Change History
comment:1 Changed 21 months ago by timmywil
- Priority changed from undecided to low
- Component changed from unfiled to event
comment:2 Changed 21 months ago by dmethvin
- Owner set to dmethvin
- Status changed from new to assigned
Since it's using the special event interface there may be a solution; I'll mark it open and look at it soon.
comment:3 Changed 20 months ago by dmethvin
- Status changed from assigned to closed
- Resolution set to fixed
This is fixed by the new IE change detection logic in 1.7.
https://github.com/jquery/jquery/commit/3bd7bed340f9077d39734ffce366ef2caeb9ce35
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

http://jsfiddle.net/timmywil/apH9c/
Confirmed, but I'm not sure we can fix this. Changing the value with javascript triggers a change in IE, but not in other browsers.