Reputation: 4065
I got this simple function in jquery/javascript that wont work in IE7, IE8:
$("input[type='checkbox']", selector).change(function() {
recalcTotalPrice(selector);
});
What is the problem with it?
Upvotes: 3
Views: 167
Reputation: 38410
In my experience observing changes of the state of check boxes is more reliably done with the click
event than with change
.
Upvotes: 0
Reputation: 8482
Everything seems fine. Here is what I tried: (working example)
HTML:
<form>
<input type="checkbox" id="c1" value="1"> <label for="c1">test</label>
<input type="checkbox" id="c2" value="2"> <label for="c2">test</label>
<input type="checkbox" id="c3" value="4"> <label for="c3">test</label>
<input type="checkbox" id="c4" value="8"> <label for="c4">test</label>
</form>
<div id="result"></div>
Javascript:
function recalcTotalPrice(s) {
var total = 0;
s.find(':checked').each(function() {
total += parseInt(this.value, 10);
});
$('#result').html(total);
}
var selector = $('form');
$("input[type='checkbox']", selector).change(function() {
recalcTotalPrice(selector);
});
Upvotes: 1