Bug Tracker

Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#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:
Blocked by: Blocking:

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 (4)

comment:1 Changed 8 years ago by timmywil

Component: unfiledevent
Priority: undecidedlow

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.

comment:2 Changed 8 years ago by dmethvin

Owner: set to dmethvin
Status: newassigned

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 8 years ago by dmethvin

Resolution: fixed
Status: assignedclosed

This is fixed by the new IE change detection logic in 1.7.

https://github.com/jquery/jquery/commit/3bd7bed340f9077d39734ffce366ef2caeb9ce35

comment:4 Changed 8 years ago by dmethvin

#8040 is a duplicate of this ticket.

Note: See TracTickets for help on using tickets.