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

12-23-2006, 07: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:


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

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


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



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

<script type="text/javascript">

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



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

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

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

But... It don't work :(

Why, i don't have a clue

12-23-2006, 09: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!!


Mr J
12-24-2006, 09: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