Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

blur event doesn't work in FireFox

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);
like image 430
Massey Avatar asked Sep 17 '25 11:09

Massey


2 Answers

Finally I have resolved it as follows:

  1. By adding an onchange event
  2. Calling a method to focus for onchange

    function setFocus(sender){ $(sender).focus(); };
like image 79
Massey Avatar answered Sep 20 '25 01:09

Massey


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?

like image 44
darkknight Avatar answered Sep 20 '25 01:09

darkknight