Reputation: 25
It seems that the following HTML and jQuery event do not work as expected in Internet Explorer. In IE the event is fired every time the radio button is clicked (even if it is the currently selected one). In Chrome it works fine. Any ideas for an IE fix?
<input id="system-open" type="radio" name="system-closure" value="false" checked="">Open
<input id="system-close" type="radio" name="system-closure" value="true">Close
$("input[name=system-closure]:radio").change(function () {
alert($(this).val());
})
Upvotes: 1
Views: 737
Reputation: 337610
You could store the previous value in a data attribute on a containing element to see if the selection has actually changed. Try this:
<div class="radio-container">
<input id="system-open" type="radio" name="system-closure" value="false" checked="">Open
<input id="system-close" type="radio" name="system-closure" value="true">Close
</div>
$("input[name=system-closure]:radio").change(function () {
var $radio = $(this);
var $container = $radio.closest('.radio-container');
var currentValue = $radio.val();
var oldValue = $container.data('old-value');
if (currentValue != oldValue) {
// the selection has been changed, do something...
alert($(this).val());
}
$container.data('old-value', currentValue);
})
Upvotes: 2