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 .

2 Answers 2

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>
Sign up to request clarification or add additional context in comments.

2 Comments

As long as the .js file is loaded before the...?
@OjonugwaOchalifu sorry, I forgot the `` arround the <button>
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();
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.