Is there a way to point a function call in HTML at a specific Javascript file? Or, am I doing something fundamentally wrong with this code?

StackOverflow https://stackoverflow.com/questions/23684389

  •  23-07-2023
  •  | 
  •  

Question

I'm pretty new to JavaScript and struggling on the basics, sadly. I've been Googling for ages to no avail and have decided I just need to now ask for help: any pointers you may have would be greatly appreciated.

File 1 (http://pastebin.com/tjFvPW1H) is an HTML file with not much going on. At the moment, it's two buttons, and you click one, and it's supposed to change some text. The code that changes that text is in 'advisor.js', which is in /js, and is included where I've been told to put it, on line 26. In the head element, before the function call. The function call itself is on line 87, and just generates 'Function not declared' errors if you click.

File 2 (http://pastebin.com/wVpx0YCv) is the JavaScript file included in File 1. I've included it in case I've made any errors there, but if I copy this code into a script block at the top of File 1, it runs fine and does what it's supposed to.

How do I get the browser to check the file I've included? Have I done/missed something monumentally stupid?

Thanks for any help given, I've been stuck with this for an hour or so, being a noob, eating Pot Noodles and Googling. I'm now all out of Pot Noodles and would like to continue working.

Thanks again!

Was it helpful?

Solution

JavaScript files ( e.g. with ".js" extension ) must not have <script type="text/javascript"> tags. Just write the code itself:

function returnComment()
{
        $.ajax({
                url: "/advisor_php/return_comment.php",
                success: function(data) {
                        $("#advisor_comment").html("<p>" + data + "</p>");
                }
        });
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top