![]() |
javascript code wont execute
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)Code:
<p id="demo"></p>Code:
<script type="text/javascript" src="index.js"></script>any help is appreciated, thanks. |
i need an answer in the next 10 mins!
|
Hi
Your script is running before your demo para is loaded so it's looking for an id that does not yet exist. try placing your script to just before closing body tag <script type="text/javascript" src="index.js"></script> </body> |
Quote:
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 |
Luckily, both Low Tech and Phillip answered after the 10 minutes were up.
<snicker style="evil" /> |
Quote:
Quote:
patient: doctor doctor, i've only got 59 secs to live! Doctor: wait a minute. seems 11 mins was just too late! |
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.
|
Quote:
|
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. |
Quote:
|
Quote:
|
| All times are GMT +1. The time now is 04:42 PM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.