Log in

View Full Version : change on click help



vacwm
05-22-2008, 04:51 PM
Hey guys, I am a the most basic beginner you have known and I need your help.

I am working on launching a small firm and I need your help in coding something
It is probably very simple...

In some of the pages on the site, I have a list of links (check the home page for example)
I am having challenges with the change on click command/ Now if you click on the link 'Mind your own business' for example, it will display certain text.
how can i make the text disappear on the second click?
this is the current code:
<a href="#" onclick="changeText(6);">Mind your own business</a><div id="text_description_6">&nbsp;</div><A>

thanks in advance

TimFA
05-22-2008, 05:22 PM
Maybe something like:

Trigger


onClick="changeText('textuwantchangedhere');"


Head code


changeText(text) {
var value=document.getElementById("div").innerHTML;

if (value=="") {
document.getElementById("div").innerHTML='' + text;
}

else {
document.getElementById("div").innerHTML='';
}
}


The area with text


<div id="div"></div>


Note that this is untested, just a guess. It works by checking to see if the DIV is empty, if it is then it inserts the text, if not then it wipes it empty. On first click add text, on second get rid of it. If the code doesn't work (likely) at least you have something to go on. If I have time and you still need it I'll try and make it work late,r assuming it doesn't now.

Good luck,
Tim

vacwm
05-22-2008, 05:37 PM
Thanks a lot man, i will be testing it tonight to see.... i will let you know if it works :)

vacwm
05-22-2008, 05:38 PM
what do you think of the site?