473,395 Members | 1,797 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

I tried to convert this Javascript to an external .js file, but it won't work...

I saved the code below to an external file which I called colorFader.js, and I'm calling it with:
<script type="text/javascript" src="js/colorFader.js"></script>

My path (above) is correct, so I'm guessing its something to do with the "onload" command at the end of the code. The code works just fine if I paste it into the <head> tag of my web page adding the standard javascript open and close <script> tags, but as soon as I save it as an external file, it breaks. If anyone could help out as to how to fix this, I would sure appreciate it, as I need to put this on several hundred pages. Thanks

-------------------------------------

Expand|Select|Wrap|Line Numbers
  1. //Created by Fader Maker (http://www.bosiljak.hr/fadermaker/)
  2. var fmTimer = null;
  3. var fmfg = false;
  4. function fminit(){
  5. if (!document.getElementById) return;
  6. fma1=0xff; fma2=0x00; fma3=0xff;
  7. fma4=0xff; fma5=0x00; fma6=0x00;
  8. if (!fmfg){
  9. fmtemp=fma1; fma1=fma4; fma4=fmtemp; fmtemp=fma2; fma2=fma5; fma5=fmtemp; fmtemp=fma3; fma3=fma6; fma6=fmtemp;
  10. }
  11. fmfg = !fmfg;
  12. fmFade();
  13. }
  14. function fmToHex(n){
  15. var hexChars = "0123456789ABCDEF";
  16. if (n == 0) return "00";
  17. var j, n;
  18. var temp = "";
  19. while (n != 0){
  20. j = n % 16;
  21. n = (n - j)/16;
  22. temp = hexChars.charAt(j) + temp;
  23. }
  24. if (temp.length < 2){
  25. temp = "0" + temp;
  26. }
  27. return temp;
  28. }
  29.  
  30. function fmFade(){
  31. obj = document.getElementById('tekst').style;
  32. fmcolor = "#" + fmToHex(fma1) + fmToHex(fma2) + fmToHex(fma3);
  33. obj.color = fmcolor;
  34. if (fma1 != fma4){
  35. if (fma4 > fma1){fma1++;}
  36. else{fma1--;}}
  37. if (fma2 != fma5){
  38. if (fma5 > fma2){fma2++;}
  39. else{fma2--;}}
  40. if (fma3 != fma6){
  41. if (fma6 > fma3){fma3++;}
  42. else{fma3--;}}
  43. if ((fma1 == fma4) && (fma2 == fma5) && (fma3 == fma6)){
  44. window.clearTimeout(fmTimer);
  45. fminit()}
  46. else{
  47. fmTimer = window.setTimeout("fmFade()",0);
  48. }
  49. }
  50. onload = fminit
---------------------------------------------------------

The HTML part of the code in the body consists of adding an <span id="tekst" > tag around the text I want to effect. </span>

Also I tried taking off the "onload = fminit" in the external file, but no luck, and I get no error codes either way.
Dec 9 '09 #1
4 2616
Dormilich
8,658 Expert Mod 8TB
have you already tried window.onload = fminit;?

you should also set breakpoints (at least FF, Safari and (I think) Opera provide debugging tools) to see, if your functions execute.
Dec 10 '09 #2
Yes, I tried that in the body tag of the webpage where I am calling the script, it doesn't seem to make any difference, I haven't tried it in the external file, is that a possibility? thanks for the suggestion. I'm not familiar with setting break points, however it doesn't work in any browser when called as an external .js file.
Dec 10 '09 #3
Dormilich
8,658 Expert Mod 8TB
I haven't tried it in the external file, is that a possibility?
that’s where you would normally place it.
Dec 10 '09 #4
that’s where you would normally place it.
I tried it, and still no luck.
Dec 11 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

22
by: Weston C | last post by:
I know of course that you can use <script src=""></script> in an HTML document to include javascript code you don't want to spill all over the page. I'm wondering if there's a way to include...
5
by: joaopedrogoncalves | last post by:
Hi, I want to load an external javascript file, get its results and stick them inside a <div> block. I also want to do this in several places on a web page. This way the browser doesn't have...
7
by: Bob Phillips | last post by:
Hope someone can help. I am struggling to write an meta element in JS. The meta element in question is the refresh element. This is the code I am using ...
136
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their...
9
by: laredotornado | last post by:
Hello, I am tasked with converting an MsAccess db to a MySQL 4 db in a Linux environment. Can anyone recommend any good freeware/scripts to help me do this? Thanks, - Dave
4
by: James Pemberton | last post by:
I have recently created a ASP site utilizing Master Pages and all works fine until I want to proces my javascripts. Just to let you know, most of cliewnt side scripting is new to me. But...
6
by: Aaron Gray | last post by:
Hi, Is there any tool that will concatinate JavaScript files compacting them spacewise and removing comment fields ? I have some sed script that sort of does the job but was wondering if there...
4
by: Neo Geshel | last post by:
I am experiencing a collision between two scripts, but I cannot find where it is. I am hoping that someone here can help me. I have two external JS files that I call into each web page. One...
4
by: donpro | last post by:
Hi, I've created a table where the header columns link to an AJAX function which calls a PHP file and returns content - the purpose is to sort the table on the heading. The code snippet is:...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.