What am I doing wrong?

Discussion in 'OT Technology' started by elamothe, Jun 22, 2005.

  1. elamothe

    elamothe New Member

    Joined:
    Apr 21, 2004
    Messages:
    214
    Likes Received:
    0
    Location:
    Canuckistan
    I'm trying to call 2 functions within the onClick(); function, and for some reason I can't get it to work.

    Basically when I click on a link, I want it to toggle the visibility of a <DIV> tag, and swap an image.

    Here's what I have in my <HEAD> tag:

    <script type="text/javascript">
    <!--
    // toggle visibility
    function toggle( targetId ){
    if (document.getElementById){
    target = document.getElementById( targetId );
    if (target.style.display == "none"){
    target.style.display = "";
    } else {
    target.style.display = "none";
    }
    }
    }
    function imgSwap ( var ) {
    if (document.var.src == "/cihiweb/en/images/arrow_right.gif"){
    document.var.src = "/cihiweb/en/images/arrow_down.gif";
    } else {
    document.var.src = "/cihiweb/en/images/arrow_right.gif";
    }
    }
    -->
    </script>

    And then on the link, I have this:

    <a href="#" onclick="toggle('whatsnew');return false; imgSwap('whatsnew_arrow');">[show/hide]</a>

    What am I doing wrong?
     
  2. elamothe

    elamothe New Member

    Joined:
    Apr 21, 2004
    Messages:
    214
    Likes Received:
    0
    Location:
    Canuckistan
    Yeah, it throws this:

    Line: 479
    Char: 1
    Error: Object Expected
    Code: 0
     
  3. dimins

    dimins I'll bring the beers ... OT Supporter

    Joined:
    Feb 13, 2002
    Messages:
    3,234
    Likes Received:
    0
    Location:
    Long Island, NY
    is line 479 this one? target.style.display = "none";
     
  4. MrMan

    MrMan New Member

    Joined:
    Jul 13, 2004
    Messages:
    308
    Likes Received:
    0
    Here is the code that I use to toggle an object hidden or visible.

    Code:
          function showhide(id)
          {
         	var style = document.getElementById(id).style;
         	if (style.visibility == "hidden")
         	{
         		style.visibility = "visible";
         	}
         	else
         	{
         		style.visibility = "hidden";
         	}
         		
         }
         

    By the way, your error is in the line
    if (document.getElementByID)
    because getElementByID is a function that requires a parameter.

    Your code should be:
    Code:
       function toggle( targetId )
      {
      	  target = document.getElementById( targetId );
      	  if (target.style.display == "none")
      	  {
      		   target.style.display = "visible";
      	  }
      	  else
      	  {
      			target.style.display = "none";
      	  }
       }
      
     
    Last edited: Jun 22, 2005

Share This Page