0

Hello,

I understand how use the onblur event the following way

<input name="city" id="city" onblur="myfunction()" />

But what if I don't want to insert javascript in html. I need to keep all javacript in a separate file. Can I execute my function without mixing html and javascript?
Thanks in advance.

3
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by Troy III
0

RYY,

//Standard
onload = function(){
  var el = document.getElementById('city');
  if(el){ el.onblur = myfunction; }
};

//jQuery
$(document).ready(function() {
  $('#city').blur(myfunction);
});

In both cases you could alternatively insert an anonymous function in place of the function name myfunction , like this :

//Standard
onload = function(){
  var el = document.getElementById('city');
  if(el){
    el.onblur = function(){
      .....
    };
  }
};

Airshow

Edited by Airshow: n/a

0

Hello,

I understand how use the onblur event the following way

<input name="city" id="city" [I][U]onblur="myfunction()" [/U][/I]/>

But what if I don't want to insert javascript in html. I need to keep all javacript in a separate file. Can I execute my function without mixing html and javascript?
Thanks in advance.

var city = document.getElementById('city')
    city.onblur = myfunction
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.