Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts

    Question Moz refuse to run a simple code

    Does anyone knows why Moz does not run the below code? No error on javascript console either...

    PHP Code:
    <!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
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    I mistyped something, yet this was not the reason. Moz does not run the code bellow:

    PHP Code:
    <!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
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,074
    Thanks
    0
    Thanked 256 Times in 252 Posts
    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.
    Code:
    function blinkB(){//blink function
      alert(document.getElementById('but').style.color);
      if (document.getElementById('but').style.color==c0){ 
         document.getElementById('but').style.color=c1 
      } 
      ...
    }
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #4
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    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)
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #5
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,074
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Quote Originally Posted by Kor
    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.
    Code:
    var flag=true;
    function blinkB(){//blink function
      document.getElementById('but').style.color=(flag)?c1:c0;
      flag = !flag;
      var settime=setTimeout('blinkB()',time); 
    }
    OO-based:
    Code:
    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();
    }
    Last edited by glenngv; 07-07-2004 at 10:31 AM.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #6
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Yes, thanks, it looks like a new Objcet(params) type function will solve the problem. TX
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •