473,809 Members | 2,687 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

3 New Member
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 2641
Dormilich
8,658 Recognized Expert Moderator Expert
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
hyperman7
3 New Member
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 Recognized Expert Moderator Expert
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
hyperman7
3 New Member
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
38566
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 other pieces of javascript code from *within* javascript.... a la #include in C, @import in Java, use/require in Perl, include()/require() in PHP, etc.... Thanks, Weston
5
5216
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 to wait for the external resource to load to show up the page, thus giving a perceiving faster load time for the user.
7
19308
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 //-------------------------------------------------------------------------- ---- function setMetaContent(metaTag, metaName, value) {
136
9468
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 code was littered with document.all and eval, for example, and I wanted to create a practical list of best practices that they could easily put to use. The above URL is version 1.0 (draft) that resulted. IMO, it is not a replacement for the FAQ,...
9
2315
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
1586
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 anyway, I can retrieve and updat ethe value a textbox on the page by using the document.getElementById('Goals_Main_tbProduct0').value
6
2596
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 were any hopefully open source tools that will do the job. I don't want encryption or obverscation though.
4
2021
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 provides me with a standards-compliant way of creating pop-up windows by simply adding a rel="external" to each anchor. The other allows me to have toggled definition lists. When the popupwin.js file is by itself, all anchors with rel="external"...
4
3681
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: <th scope="col"><a href="javascript:;" onclick="loadBookingContent('<? php echo $SERVERPAGE_URL . SORT_BY_BOOKING; ?>','innerhbl')">Booking</ a></th>
0
9721
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10376
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10383
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7661
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5688
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4332
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3861
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3015
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.