PDA

View Full Version : How many tricks to ...



shachi
07-09-2006, 08:05 PM
Can anyone post some tricks for making something like a toggle button?? Like a link which does two actions(onclick). If you click it once it expands a div and if you click again it contracts. I have been trying to do that for ages but what I found was one of the scripts in w3schools which is sth like:



var cc=0;
if(cc=0){
cc=1;
//do something
} else {
cc=0;
//do something
}


If anyone has any other tricks then please post them in this thread.:p

Twey
07-09-2006, 10:40 PM
If the actions set a variable, all you have to do is check that one.

jscheuer1
07-15-2006, 05:51 AM
Here's one:

http://www.dynamicdrive.com/forums/showpost.php?p=43440&postcount=5

shachi
07-15-2006, 08:21 AM
Thanks Twey, jscheuer1 I am looking forward to some more tricks.:)

Twey
07-15-2006, 01:40 PM
I think NTL (big British broadband provider, similar to AOL in America) have decided it's Experience Life as a Snail week -- my connection currently measures at 715 bytes per second. Anyway...

You can also toggle the whole event:
<button id="btn">A button</button>
<script type="text/javascript">
function toggleOn() {
// do something
this.onclick = toggleOff;
}

function toggleOff() {
// do something else
this.onclick = toggleOn;
}

document.getElementById("btn").onclick = toggleOn;
</script>All depends on what you want to do and what else you've got to measure by.

shachi
07-15-2006, 06:27 PM
Ah!! Twey I have never seen any of that kind. LOVE IT!!!!