Solved

Why does this script not work in this site

Posted on 2014-02-20
2
296 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

706 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now