Reputation: 13
I have a particular piece of jQuery that is working fine in IE9, Chrome and Firefox, etc, however IE8 seems to particularly dislike it:
<script type="text/javascript">
$("#bandwidth").ForceNumericOnly();
$("#bandwidth").on("input", function() {
var total = this.value*0.18;
$('#total').val('£'+ total.toFixed(2));
});
</script>
This takes the input from the bandwidth input, calculates accordingly and then writes to the total input, prefixed with £.
It doesn't seem to perform the calculation in to the total input which is really confusing me.
Upvotes: 0
Views: 75
Reputation: 3513
For IE8 you may want to have a combination of keyup keydown events or propertychange event ... acts like input event and was added from IE6+
Maybe this will help :
$(function(){
$('#helloMama').on('propertychange', function(e){
var $this = $(this);
$('#output').text("cought by IE6+ :"+$this.val());
});
$('#helloMama').on('input', function(e){
var $this = $(this);
$('#output').text("cought by smarties: "+$this.val());
});
});
Upvotes: 0
Reputation: 135
DEMO http://jsbin.com/acigaj/2
You can use the keyup event this event works fine in IE7+
$("#bandwidth").on("keyup", function() {
var total = this.value*0.18;
$('#total').val('£'+ total.toFixed(2));
});
Edit: If you want restrict the input field to numbers only? Then you can do something like this.
DEMO: http://jsbin.com/acigaj/5/edit
$("#bandwidth").on("keyup", function() {
this.value = this.value.replace(/[^0-9]/,'');
var total = this.value*0.18;
$('#total').val('£'+ total.toFixed(2));
});
Upvotes: 3