1

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);
2
  • 3
    Move it to a JS file. Commented Dec 8, 2013 at 20:26
  • If one of the pages is in an iframe, you can call its functions from the parent window. Commented Feb 27, 2022 at 12:48

1 Answer 1

4

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.