Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Why does this script not work in this site

Posted on 2014-02-20
2
307 Views
Last Modified: 2014-02-24
I am trying to display some customer reviews on this site.  Its is supposed to auto rotate the reviews. Its built in Dreamweaver. For some reason the below script is not being called. http://basementauthoritiesnh.com/. It should be displaying under Customer Comments

Here is my code:

one the homepage I have div tag

<div id="testimonials" class="transparent_class"></div>

and css for the transparent_class is

transparent_class {
    font-size:13px;
    height:80px;
    width:680px;
}

for the javascript
var Testimonials = [
	['Sample text <br> <b> - John</b>'],
	['Sample text <br> <b> - Jane</b>']
	
				// Note: no comma after last entry
	];
	
var fileInx = 0;
var fadeCnt = 0;
var fadeInc = 5;

function dispTestimonial () {
  document.getElementById("testimonials").innerHTML = Testimonials[fileInx]; // +'<p>'+fadeCnt;
  document.getElementById('testimonials').style.opacity = (fadeCnt/30).toFixed(2);
  document.getElementById('testimonials').style.filter = 'alpha(opacity=' + fadeCnt + ')';
  fadeCnt += fadeInc;
  if (fadeCnt >= 100) { fadeInc *= -1; }
  if (fadeCnt <= 0) {
	fadeInc *= -1;   
    fileInx++;
    fileInx = (fileInx % Testimonials.length);  
  }
}

window.onload = function () {
  dispTestimonial()
  setInterval("dispTestimonial()", 400);
}

Open in new window

I am trying to display what in the  Testimonials

Thanks
0
Comment
Question by:niceoneishere
2 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 39874398
window.onload can be overwritten by an other window.onload (in fact the one present in your body tag)

use this instead :
var Testimonials = [
	['Sample text <br> <b> - John</b>'],
	['Sample text <br> <b> - Jane</b>']
	
				// Note: no comma after last entry
	];
	
var fileInx = 0;
var fadeCnt = 0;
var fadeInc = 5;

function dispTestimonial () {
  document.getElementById("testimonials").innerHTML = Testimonials[fileInx]; // +'<p>'+fadeCnt;
  document.getElementById('testimonials').style.opacity = (fadeCnt/30).toFixed(2);
  document.getElementById('testimonials').style.filter = 'alpha(opacity=' + fadeCnt + ')';
  fadeCnt += fadeInc;
  if (fadeCnt >= 100) { fadeInc *= -1; }
  if (fadeCnt <= 0) {
	fadeInc *= -1;   
    fileInx++;
    fileInx = (fileInx % Testimonials.length);  
  }
}

var f = function() {
	dispTestimonial()
	setInterval(dispTestimonial, 400);
}

if(window.addEventListener) {
	window.addEventListener('load', f, false);
}
else if (window.attachEvent) {
	window.attachEvent('onload', f);
}

Open in new window


https://developer.mozilla.org/en/docs/DOM/element.addEventListener
0
 
LVL 1

Author Closing Comment

by:niceoneishere
ID: 39883923
Thanks
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
html input 8 42
How  can  I extract  Id  from a  URL  using  Javascript? 12 29
Responsive Font Size 6 26
How to control cache of some js files ? 7 39
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question