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.

Recommended Answers

All 2 Replies

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

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
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.