Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi, I have some javascript imbedded in my home page and I want to put it into a separate .js file. I have searched this forum and also googled it but none of the techniques I have found seem to work.. I wonder if anyone could tell me exactly what i need to put in the <head> section and then what i need to onload in the <body> (if anything), and lastly what i need to place in the html to call the javascript to work in the right place.
Here is the URL, the javascript starts on line 170
http://www.anxiety2calm.com/newinde...

Simple.
For any acripts that you want in an external page just copy everything between the opening <script> tag and the ending </script> tag (do NOT copy the script tags themselves) and put it into a text file (using notepad). Then just name the file something descriptive with a ".js" extension. (Actually you can use any extension, but "js" conforms to the standards).
Then in the head or body of your HTML file you just use the same script tags as before but include a "src" in the opening tag. This directs the page to load the external file as the content between the opening and closing tag. Like this:
<script language="javascript" src="filename.js"></script>You do not need to modify any of the javascript triggers in your HML, such as onClick events.
Hope this helps.
Michael J

Mike, your a genious when it comes to the web stuff. Do you have any sites up that show off your ability?

Hi Michael! Thanks a lot for your reply, but unfortunately it hasn't solved my problem. Now the javascript section is out of position and i can't see how to position it on the screen, and also it doesn't work, the messages do not fade in and out.
http://www.anxiety2calm.com/newinde... is how it should look...in this example the javascript is imbedded into the html.
http://www.anxiety2calm.com/newinde... is the version with a separate .js file
Any more help would be great!
Thanks for your time
thomas

chantaspell1977,
In the version witht he separate js file, put this (<script language="javascript" src="fader.js"></script>) in the exact same position as the embeded script exists in the first file.
Whereever you include a script tag is where it will be interpreted/loaded - does that make sense?
"Mike, your a genious when it comes to the web stuff. Do you have any sites up that show off your ability?"
Thank you very mauch. Most of what I have learned has been through work done through my employers (mostly in the past). But, I still do quite a bit mostly for personal enjoyment. About the only thing I could direct you to is a gaming site: http://repeat-offenders.org
The most notable things on there are the Teamspeak block (which heavily utilizes DHTML) and the BF2 Server block and module pages. Both of the above display data dynamically based upon server queries.
Michael J

Hi! Thanks for the tip, but this only solved part of the problem...now the table is appearing in the right place, but the text still doesn't fade to new text, it is just stationary text. For some reason the .js file seems to not be functioning!
Any ideas?
Many many thanks
thomas

chantaspell1977,
Not to be rude, but it is very difficult to help someone with code like this when you change the code! Doh!
For example in the function colorfade the original code had this:
if(step<=maxsteps)
In the 2nd example with the exteranl js file it was changed to this:
if(step=maxsteps)
Although that doesn't look much different, it is COMPLETELY different. When evaluating if two values are equal you need to use double equal signs. By using a single equal sign you are assigning step to be equal to the value of maxsteps instead of testing if it is equal.
I tested this locally and once I replaced the contents of the external js file with the code from the working page, everything is working correctly.
Michael J

Oooooops!!
You are a genious and I am a muppet! What can I say?
Thanks a million for helping me with this!
It is appreciated.cheers
thomas

My pleasure.
And, just as an FYI, it is the usual standard (but not required) that javascript function and other code be placed in the HEAD of the document. In this case I would have pulled out all of the code and done an include in the head of the document and just put the required line(s) inline to call the necessary functions.
In this case, I didn't want to confuse the issue by adding in another level of complexity.
Michael J

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |