...

View Full Version : Moz refuse to run a simple code



Kor
07-07-2004, 10:22 AM
Does anyone knows why Moz does not run the below code? No error on javascript console either... :eek:



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<script>
c0='#000000'//first color
c1='#FF0000';//second color
time=1000;//blinking interval in milliseconds

function setC(){//sets the first color onload
document.getElementById('but').style.color=c0-;
blinkB()
}
function blinkB(){//blink function
if (document.getElementById('but').style.color==c0){
document.getElementById('but').style.color=c1
}
else{document.getElementById('but').style.color=c0}
var settime=setTimeout('blinkB()',time);
}
window.onload=setC
</script>
</head>

<body>
<input name="but" type="button" id='but' value="Button">
</body>
</html>

Kor
07-07-2004, 10:27 AM
I mistyped something, yet this was not the reason. Moz does not run the code bellow:



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<script>
c0='#000000'//first color
c1='#FF0000';//second color
time=1000;//blinking interval in milliseconds

function setC(){//sets the first color onload
document.getElementById('but').style.color=c0;
blinkB()
}
function blinkB(){//blink function
if (document.getElementById('but').style.color==c0){
document.getElementById('but').style.color=c1
}
else{document.getElementById('but').style.color=c0}
var settime=setTimeout('blinkB()',time);
}
window.onload=setC
</script>
</head>

<body>
<input name="but" type="button" id='but' value="Button">
</body>
</html>

glenngv
07-07-2004, 10:44 AM
If you would only alert what the exact value is, you would know that what you set may not be exactly what the actual value would be. This is especially true for setting CSS properties such as color, border, etc.


function blinkB(){//blink function
alert(document.getElementById('but').style.color);
if (document.getElementById('but').style.color==c0){
document.getElementById('but').style.color=c1
}
...
}

Kor
07-07-2004, 11:10 AM
Yes, I have notice myself that a little bit later. As I work with Moz only for a couple of mounth I have never notice that Moz returns the style.color in RGB mode, not in hexa mode... I wonder:

1. which is the standard (or recomended) color value ?
2. Is there a cross-browser way to solve this (except the string value which, I see, it works for both, ie: "blue", "white" - which is a limited color value reference)

glenngv
07-07-2004, 11:29 AM
2. Is there a cross-browser way to solve this (except the string value which, I see, it works for both, ie: "blue", "white" - which is a limited color value reference)
Use a flag.


var flag=true;
function blinkB(){//blink function
document.getElementById('but').style.color=(flag)?c1:c0;
flag = !flag;
var settime=setTimeout('blinkB()',time);
}

OO-based:


function Blink(id, color1, color2, time){
var me = this;
this.obj = document.getElementById(id);
this.color1 = color1;
this.color2 = color2;
this.time = time;
this.flag = true;
this.obj.style.color = color1;
this.timer = null;
this.startBlink = function(){
me.obj.style.color = (me.flag) ? me.color2:me.color1;
me.flag = !me.flag;
me.timer = setTimeout(function(){me.startBlink()}, me.time);
}
this.stopBlink = function(){
clearTimeout(me.timer);
}
}

window.onload = function(){
var btn1 = new Blink('but', '#000000', '#FF0000', 1000);
btn1.startBlink();
}

Kor
07-07-2004, 11:45 AM
Yes, thanks, it looks like a new Objcet(params) type function will solve the problem. TX



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum