I have
var x = new Array()
x[0] = ‘text 0’
x[1] = ‘text 1’
and somewere in code an if statement:
if(document.getElementById(‘anid’).innerHTML == x[1])
Everythig works OK. Now, if I use another type of string
var x = new Array()
x[0] = ‘<img src=”0.jpg”>’
x[1] = ‘<img src=”1.jpg”>’
The if satement woun’t work (I mean it works as if those two strings, innerHTML and the x value are [b]never
Any ideea?
Here’s the whole script. It rotates proportional / random some objects. If simple text, is ok, but if pictures the first [b]break
[code=php]
<html>
<head>
<script>
var c = new Array(50,50,90) // Add as many values, but the same number with var inn
var inn = new Array() // Add as many values, but the same number with var c
inn[0] = ‘<img src=”25.jpg”>’;
inn[1] = ‘<img src=”26.jpg”>’;
inn[2] = ‘<img src=”27.jpg”>’;
var timeout = 2000; // set de delay (miliseconds)
// No need any changes below
var tot = 0;
var aa = 0;
for (i=0;i<c.length;i++){
tot = tot+c[i];
}
cc = new Array()
for (i=0;i<c.length;i++){
cc[i] = c[i]/tot*100;
}
qq = new Array()
for (i=0;i<c.length;i++){
qq[i] = aa+cc[i];
aa=qq[i]
}
function slide(){
var rr=Math.floor(Math.random()*101);
for (i=0;i<c.length;i++){
if(rr<=qq[i]){
if(document.getElementById(‘x’).innerHTML == inn[i]){alert(‘1’); break}
else{document.getElementById(‘x’).innerHTML = inn[i];alert(‘2’);
break}
}
}
setTimeout(‘slide()’,timeout)
}
</script>
</head>
<body onload=”slide()”>
<div id=”x”></div><br>
</body>
</html>
Use first
inn[0] = ‘text 00’;
inn[1] = ‘text 01’;
inn[2] = ‘text 02’;
When simple text, the alert(‘1’) shows whenever the random number keeps the same object. So the code is OK. When pictures instead of simple text, the first break woun’t work (the first if statement is somehow incorrect). Any ideeas?