View Single Post
Join Date: Jun 2008
Posts: 130
Reputation: Q8iEnG is an unknown quantity at this point 
Solved Threads: 2
Q8iEnG Q8iEnG is offline Offline
Junior Poster

Trying to change this JavaScript code, to work without External File..!! How?? plz

 
0
  #1
Dec 1st, 2008
Hi guys..

I'm still on my way on learning and seeing examples of JavaScript Codes

Today I saw this code (which depends on external file called *banner.js*)

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <!-- Paste this code into an external JavaScript file named: banner.js.js -->
  2.  
  3. /* This script and many more are available free online at
  4. The JavaScript Source :: http://javascript.internet.com
  5. Created by: Lee Underwood :: http://javascript.internet.com/ */
  6.  
  7. var bannerImg = new Array();
  8. // Enter the names of the images below
  9. bannerImg[0]="image_jss.gif";
  10. bannerImg[1]="image_js.gif";
  11. bannerImg[2]="image_wr.gif";
  12.  
  13. var newBanner = 0;
  14. var totalBan = bannerImg.length;
  15.  
  16. function cycleBan() {
  17. newBanner++;
  18. if (newBanner == totalBan) {
  19. newBanner = 0;
  20. }
  21. document.banner.src=bannerImg[newBanner];
  22. // set the time below for length of image display
  23. // i.e., "4*1000" is 4 seconds
  24. setTimeout("cycleBan()", 4*1000);
  25. }
  26. window.onload=cycleBan;
  27.  
  28.  
  29.  
  30. <!-- Paste this code into the HEAD section of your HTML document.
  31. You may need to change the path of the file. -->
  32.  
  33. <script type="text/javascript" src="banner.js.js"></script>
  34.  
  35.  
  36.  
  37. <!-- Paste this code into the BODY section of your HTML document -->
  38.  
  39. <img src="image_jss.gif" name="banner">
  40. <p><div align="center">
  41. <font face="arial, helvetica" size"-2">Free JavaScripts provided<br>
  42. by <a href="http://javascriptsource.com">The JavaScript Source</a></font>
  43. </div><p>


I've tried to make it work without using (external file), but it doesn't work!!! please anyone can tell me where's my mistake?
here's my code
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <script type="text/javascript"> // adding the JavaScript prototype
  2.  
  3. var bannerRotate = new Array(); // creating new Array named "banner", and we set its value to unknown by saying * new Array() *
  4. // Here you can create a list of whatever, images you want to add..
  5. bannerRotate[0] = "image.gif";
  6. bannerRotate[1] = "image2.gif";
  7. bannerRotate[2] = "image3.gif";
  8.  
  9. var getNewBanner = 0;
  10. var total = bannerRotate.length;
  11.  
  12. function rotate()
  13. {
  14. getNewBanner++;
  15.  
  16. // if statement to check the condition getNewBanner == to the total number of images, or not? if yes, then starts again from ZERO
  17. if( getNewBanner == total )
  18. {
  19. getNewBanner = 0;
  20.  
  21. }
  22.  
  23. document.banner.src=bannerRotate[ getNewBanner ];
  24. setTimeout = ( "rotate()", 4*1000 );
  25.  
  26. } // end function rotate
  27.  
  28. window.onload = rotate();
  29.  
  30. </script>

here's the code in <body>
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <img src="image.gif" name="banner">


waiting for the help to keep learning from my mistakes

thanks in advance
Reply With Quote