Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Dec 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    changing javascript to work with image instead of inputbox

    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

  • #2
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts
    Give this a try

    PHP Code:
    <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> 
    The silent one.

    The most dangerous thing in the world is an idea.
    The most dangerous person in the world is the one with an idea.

  • #3
    New to the CF scene
    Join Date
    Dec 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for your reply!

    But... It don't work

    Why, i don't have a clue

  • #4
    New to the CF scene
    Join Date
    Dec 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #5
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts
    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
    }
    The silent one.

    The most dangerous thing in the world is an idea.
    The most dangerous person in the world is the one with an idea.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •