0

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 .

Community
  • 1
  • 1
Ojonugwa Jude Ochalifu
  • 23,935
  • 25
  • 104
  • 122

2 Answers2

1

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>
Lux
  • 16,183
  • 3
  • 36
  • 64
0

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();
});
T J
  • 40,740
  • 11
  • 73
  • 131