...

View Full Version : changing javascript to work with image instead of inputbox



djazzz
12-23-2006, 06:46 PM
Hi People,

I am completely new to javascripting. I was wondering if someone could help me change this javascript. Now it uses a inputbox to toggle a div visible and invisible. I now want it to toggle when i click on a image.
I tried to change type to image, that works, only i cannot toggle back, the div stays hidden!

the inputbox:

<input id="inp1" onclick="ToggleVisibility();" type="checkbox" checked="true" >Show DIV</input>

the code:

<script>

function ToggleVisibility()
{
var objInp = document.getElementById("inp1");
var objDiv = document.getElementById("div1");

if (objInp.checked) objDiv.style.visibility = ""; else objDiv.style.visibility = "hidden";
}

</script>

So, does anybody know a workaround?
I want to use this script, because i embedded a flash mp3player in the div, and this script allows the player to stay playing if the div is invisible!!

thanks
:(

Djazzz

Mr J
12-23-2006, 08:02 PM
Give this a try


<script type="text/javascript">

function ToggleVisibility(){
var objDiv = document.getElementById("div1")

if(objDiv.style.visibility=="visible"){
objDiv.style.visibility="hidden"
}
else{
objDiv.style.visibility="visible"
}

}
</script>

<img src="yourimage.jpg" onclick="ToggleVisibility()">

<div id="div1" style="visibility:visible">Hello World</div>

djazzz
12-23-2006, 08:30 PM
Thanks for your reply!

But... It don't work :(

Why, i don't have a clue

djazzz
12-23-2006, 08:36 PM
Sorry ,my fault, it does work, i changed the style to hidden and now it works!!!

thanks a lot

If you happen to know why it works, please let me know!!

djazzz

Mr J
12-24-2006, 08:04 AM
The script really explains itself

if(the div is visible){
make the div invisible
}
else{ // if it is not visible it must be hidden so
make the div visible
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum