Forum Moderators: open
I have a block of javascript in a Joomla site-- it's built into the view (in an MVC structured component) and it gets included into the template file, which is where most of the HTML is.
The Javascript I'm trying to fire is in the view block in a window.addEvent('domready',function(){}). So the code basically looks like:
window.addEvent('domready',function(){
function myFunction(){
alert("it works");
}
})
I want to call this function from an onChange event in the html template like this:
<input onBlur="myFunction()" type="text" class="inputbox" name="search" value="value">
I also tried
<input onBlur="myFunction();" type="text" class="inputbox" name="search" value="value">
and
<input onBlur="this.myFunction()" type="text" class="inputbox" name="search" value="value">
and
<input onBlur="window.myFunction()" type="text" class="inputbox" name="search" value="value">
but no matter what format I've tried Firebug tells me "myFunction is not defined" or "this.myFunction is not a function".
I know this is probably a scoping issue and a simple one at that, but I'm stumped. Thanks for any help.
window.addEvent('domready', function () {
myFunction = function () {
alert("it works");
}
});
This creates a global variable, myFunction, which holds a reference to your anonymous function.