Reputation: 489
I have 2 files, one HTML, one JavaScript.
JavaScript File (contacts.js):
function add_contact() {
// Rest of Code here
}
HTML File:
<script src="/assets/js/contacts.js" type="javascript/text"></script>
I have a button that when it's clicked, it calls the 'add_contact' function:
<button type="button" class="btn btn-primary" onclick="add_contact();">Save changes</button>
When the JavaScript code is the head of the HTML file, the function works fine. However, now it's part of the external file, it returns the following error:
Uncaught ReferenceError: add_contact is not defined
I feel a bit lost over this one, so any help would be fantastic!
Upvotes: 7
Views: 4919
Reputation: 5319
Change this block of markup:
<script src="/assets/js/contacts.js" type="javascript/text"></script>
to:
<script src="/assets/js/contacts.js" type="text/javascript"></script>
Upvotes: 3