With parenthesis ()
, you are calling onfocusFunction
function and assigning undefined
to myMail.onfocus
:
myMail.onfocus = undefined;
as your onfocusFunction
function does not return anything.
Without parenthesis, you will have onfocusFunction
object, which should be assigned to .onfocus
:
myMail.onfocus = onfocusFunction; //No parenthesis before ';'
UPDATE: If you want to pass parameters either, then try like this:
function onfocusFunction(param1,param2) {
return function(){
alert(param1+":"+param2);
};
}
var myMail = document.getElementById('mail');
myMail.onfocus = onfocusFunction("value1","value2");
Then when onfocus
event will be triggered you will see "value1:value2"
as an alert.