I am trying to execute this javascript here and get it to show the value in a paragraph. It works when i put it inside my html file, however as soon as a link to it in an external js file, it doesn't work. Why is this? Need help desperately! Thank you
JS code multiplying a by b and then displaying the value in a paragraph with an id of "demo":
Code:
function myFunction(a,b)
{
return a*b;
}
document.getElementById("demo").innerHTML=myFunction(4,3);
What exactly is keeping this from working in an external javascript file? The javascript code is functional when placed within my HTML file, so why not my JS file?
Two possible reasons why the external file will not work:
a) It is placed in the wrong directory.
b) It contains HTML tags such as <script>
Also, the para with id "demo" must exist before the script is run. So you must place the call to your external file after the para. That is one reason why it is best to place scripts immediately before the </body> tag.
It is your responsibility to die() if necessary….. - PHP Manual
__________________
All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
Asking on a forum is not the thing to do when you need an answer that quickly. Particularly when you are asking on a weekend when the forum is quieter than during the week.
Asking on a forum is not the thing to do when you need an answer that quickly. Particularly when you are asking on a weekend when the forum is quieter than during the week.
I get the impression that quite a few newcomers imagine that unpaid experts are standing around 24/7 just to answer their questions.
__________________
All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
Even worse are those who think it's okay to either do nothing on their own or to post a big chunk of code, of course without code tags and no formatting whatsoever, and be like "okay, now you do this for me".
If you want someone to take the time to help, take the time to ask right.