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 4 of 4
  1. #1
    Regular Coder RexxCrow's Avatar
    Join Date
    Jul 2006
    Location
    California
    Posts
    275
    Thanks
    6
    Thanked 2 Times in 2 Posts

    Firefox ignoring a portion of small function

    The highlighted portion is ignored and I feel it has something to do with the about and contact, but am at a loss as to how to remedy this, I can get it to work in IE but that is all (by removing the ' ''s from that text), any ideas as to were my flaw(s) are in in this function? TIA

    Code:
    <script language="javascript" type="text/javascript"><!--
    function goVis(swap){
    getV=document.getElementById(swap)
    if(getV=='contact'&&about.style.display=='block'){
     about.style.display='none'
    }
    if(getV=='about'&&contact.style.display=='block'){
     contact.style.display='none'
    }
    if(getV.style.display=='none'){
     getV.style.display='block'
    }else{
     getV.style.display='none'
     }
    }
    //--></script>

  • #2
    Regular Coder
    Join Date
    Jul 2007
    Location
    UK
    Posts
    223
    Thanks
    0
    Thanked 14 Times in 14 Posts
    document.getElementById() will return an object (if it finds one and null if it doesn't) so getV=='contact' and getV=='about' will always be false. Try alert(getV); to proove this.

    You could do something like this:
    Code:
    <script type="text/javascript"><!--
    function goVis(swap){
     var getV=document.getElementById(swap); //returns an object.
     
     if(swap=='contact'&&document.getElementById('about').style.display=='block'){
      document.getElementById('about').style.display='none';
     }
     else if(swap=='about'&&document.getElementById('contact').style.display=='block'){
      document.getElementById('contact').style.display='none';
     }
     if(getV.style.display=='none'){
      getV.style.display='block';
     }else{
      getV.style.display='none';
     }
    }
    //--></script>
    I've not tested it, but I think it should work.

  • Users who have thanked mcjwb for this post:

    RexxCrow (08-22-2007)

  • #3
    Regular Coder RexxCrow's Avatar
    Join Date
    Jul 2006
    Location
    California
    Posts
    275
    Thanks
    6
    Thanked 2 Times in 2 Posts
    Alright that worked like a charm, thanks for the help on that, so strings and objects don't mix then; I knew it had something to do with the string, though I thought I had to declare a specific type of variable, well at least I am learning, slowly but surely, heh.

  • #4
    Regular Coder
    Join Date
    Jul 2007
    Location
    UK
    Posts
    223
    Thanks
    0
    Thanked 14 Times in 14 Posts
    Javascript is a loosely typed language so you can assign anything to any variable.


  •  

    Posting Permissions

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