I have an asp.net mvc page. I have a textbox which when a value is entered, and went off of the box should execute a javascript function which will roundup the value in the textbox. This works fine in Chrome and IE but not in FireFox.
The following is the code. setAmount() is the javascript function which is supposed to be executed.
<div class="amount-other-input">
<div class="bold-label" style="margin-right:5px;">£</div>
<input id="amountOther" type="number" name="other" onblur="setAmount(this)" class="numbersOnly" maxlength="4">
</div>
I tried in adding a timer as suggested in another stackoverflow answer as shown below, but didin't work:
document.getElementById('amountOther').addEventListener("blur", function() {
var element = this;
setTimeout(function() {
setAmount(element);
}, 1);
}, true);
Finally I have resolved it as follows:
Calling a method to focus for onchange
function setFocus(sender){ $(sender).focus(); };As mentioned by @Hobo Sapiens, don't add the blur event on both the html and event listener. Just call the function directly on the onblur
event from the html.
Here is a fiddle for it: http://jsfiddle.net/pyjtL456/2/
Also, what version of firefox are you checking this on?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With