user2964960
user2964960

Reputation: 29

call function in another HTML file

I am trying to call another function in a different HTML file would I do something like this:

 <script type = "text/javascript" src = "otherfile.html"></script>

This is the function getting called

        function rankedScores(music, pattern) { 
            var scoresArray = urlScores(music, pattern);  

            function swap(a, b) {
                var temp = scoresArray[a];
                scoresArray[a] = scoresArray[b];
                scoresArray[b] = temp;
            }

            for(var i = 0; i < scoresArray.length; i++) {
                for(var x = 0; x < scoresArray.length - 1; x++) {

                    if (scoresArray[x].score > scoresArray[x + 1].score) {
                        swap(x, x + 1);
                    }
                }
            }
            generateResults(scoresArray)
        }

This is how im calling it:

       rankedScores(albums, document.main.search.value);

Upvotes: 1

Views: 9132

Answers (1)

Ryan Bigg
Ryan Bigg

Reputation: 107728

You cannot do this. You should move it into a js file and then include that js file in your template:

<script type='text/javascript' src='some_other_file.js'></script>

Upvotes: 4

Related Questions