Waqas
Waqas

Reputation: 434

How to call or attach js function on "onblur" of input in Wordpress

I am trying to call a function on onblur event of a textbox. I tried calling it inline but that didn't work so I added all the js in a separate file and tried to add EventListener on the textbox but that's not working. Here is my code. This is how my js starts:

jQuery(document).ready(function($){
    document.getElementById("Ex").addEventListener("onblur", function(){
        CalculateTax();
    });   
});    

function CalculateTax() {   
    /// Code
}

Upvotes: 0

Views: 501

Answers (1)

RajM
RajM

Reputation: 61

Can you try adding event listener in following manner:

 jQuery(document).ready(function($){
       jQuery(document).on("blur", "#Ex", function(){
           CalculateTax();
       });
   });

Upvotes: 2

Related Questions