Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

External JavaScript function undefined, but exists

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!

like image 744
Parker1090 Avatar asked Jan 13 '15 18:01

Parker1090


1 Answers

Type should be text/javascript not javascript/text

like image 153
James McDonnell Avatar answered Sep 20 '22 03:09

James McDonnell