Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call a function only when fired by an event

I have the following function:

format : function(){
   //function body
   if(condition){
       //execute this condition only on focus event 
   }
}

This function is being called on page load and on the focus of an input element. I have a condition within this function that I would like to be called only when this function is called manually from the focus event and not on page load. Is there a way to achieve this?

There are cases sometimes when the 'condition' in the if statement is true on page load as well. Any help will be appreciated. Thanks in advance.

like image 377
pj013 Avatar asked Apr 28 '26 17:04

pj013


1 Answers

Separate into two functions:

format: function() {
    //Do stuff for focus
}
onload: function() {
    //Do stuff for onload
    this.format();
}
like image 198
Madara's Ghost Avatar answered May 01 '26 06:05

Madara's Ghost