PHP multiple Js.files?

A question I have is about PHP and Javascript. So when I have multiple php-pages it seems it gets a bit wrecked when I try to link to only ONE Js.file inside the folder. Do I need one js.file for every PHP-page for it all to work?

For example, I know the code works. But if I load one php-page where that code is not located it gives me errors. But that code is linking a different PHP-page to the JS.file. Which is why it should not give an error. But it says “missing” or something.