Reputation: 27256
Let me start by saying this is kind of a duplicate to this question:
run function when page is loaded.
But the difference is, while the referenced question includes the javascript function in a html code, i want to know how to use a function from a .js
file in my .html
file without including the entire function which is quite bulky.
I have tested this function by adding it to an event that is triggered when i click a button (function retrieves data from a Google App Engine server)
$ (document).ready(function() {
$("#showMembers").bind('click', function(event) {
event.preventDefault();
doViewMembersRequest();
}); });
What i need is a way to call doViewMembersRequest();
from my viewmembers.html
file .
Upvotes: 0
Views: 118
Reputation: 18240
I dont exactly understand what u wanna do!
But the following code will also work if myFunction
is in an .js file, as long this .js file is loaded before the <button>
and the function is not declared in an $(function() {});
!
<button onclick="myFunction()">Click me</button>
Upvotes: 1
Reputation: 43166
Just link to the js file in your html page like <script src='yourJsFile.js'></script>
and call the function on ready()
$ (document).ready(function() {
doViewMembersRequest();
});
Upvotes: 0