...

View Full Version : How can i revert an action on second click?



Kor
06-03-2003, 02:58 PM
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....

Garadon
06-03-2003, 04:07 PM
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 :)




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

Kor
06-03-2003, 04:24 PM
thanks, i forgot about those small caps and equivalency ==. Thank you again :-) It works.

Mr J
06-03-2003, 04:49 PM
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>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum