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 4 of 4
  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

    How can i revert an action on second click?

    i wanna, for instance, change the style color, something like this:

    function objectSetup() {
    zclic = new layerSetup("clic","#FF0000");
    }
    function layerSetup(id,color){
    this.obj = document.getElementById(id).style;
    this.obj.color = color;
    return this.obj;
    }
    function culoare(){
    var zwclic = zclic.color;
    if(zwclic = "#FF0000"){
    zclic.color = "#0000FF";
    }
    else if(zwclic = "#0000FF"){
    zclic.color = "#FF0000";
    }
    }


    and in body

    <body bgcolor onload="objectSetup()">
    <a href="#" id="clic" onclick="culoare(); return false">CLICK</a>
    </body>

    The color chages first time, and that is all....
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #2
    Regular Coder
    Join Date
    Jul 2002
    Posts
    698
    Thanks
    0
    Thanked 0 Times in 0 Posts
    the following works. javascript assign values to variables if u only use one '=' also in the if sentece. and the hax values are stored in smalll letters


    Code:
     
    <script>
    function objectSetup() {
    zclic = new layerSetup("clic","#FF0000");
    }
    function layerSetup(id,color){
    this.obj = document.getElementById(id).style;
    this.obj.color = color;
    return this.obj;
    }
    function culoare()
    {
      var zwclic = zclic.color;
      alert(zwclic);
      if(zwclic == "#ff0000")
    	{
        zclic.color = "#0000FF";
      }
      else if(zwclic == "#0000ff")
    	{ 
        zclic.color = "#FF0000";
      }
    }
    
    </script>
    
    <body bgcolor onload="objectSetup()">
    <a href="#" id="clic" onclick="culoare(); return false">CLICK</a> 
    </body>

  • #3
    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

    Unhappy Thanx

    thanks, i forgot about those small caps and equivalency ==. Thank you again :-) It works.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #4
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts
    The following is slightly shorter and allows each link color to be changed if required



    <script>
    function colour_me(id,col){
    if(document.getElementById(id).style.color=="#ff0000"){
    document.getElementById(id).style.color=col
    }
    else{
    document.getElementById(id).style.color="#ff0000"
    }
    }
    </script>


    <a href="#" id="clic" onclick="colour_me(this.id,'#0000ff'); return false" style="color:#ff0000">CLICK 1</a>
    <P><a href="#" id="clic2" onclick="culoare(this.id,'#ff00ff'); return false" style="color:#ff0000">CLICK 2</a>


  •  

    Posting Permissions

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