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 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jul 2003
    Posts
    601
    Thanks
    17
    Thanked 0 Times in 0 Posts

    Toggling visibility w/Javascript

    Hey All,

    I have this function, which toggles the visibility of a drop down menu. This currently works:

    function toggleOther(chosen) {
    if (chosen == 'Warren') {
    document.myForm.WarrenBldg.style.visibility = 'visible';
    document.myForm.WarrenBldg.value = 'East';
    } else {
    document.myForm.WarrenBldg.style.visibility = 'hidden';
    document.myForm.WarrenBldg.value = '';
    }
    }


    <select name="OfficeLocation" class="textbox" onChange="toggleOther(document.myForm.OfficeLocation.options[document.myForm.OfficeLocation.selectedIndex].value);">


    I'm trying to do something similar with a simple link. If the user clicks the link once, this drop down appears. If they click it again, it disappears.

    I have the right idea I think, but the wrong code/syntax.

    Any help would be appreciated.

    Thanks.

  • #2
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    I persoannly would do it this way
    Code:
    function toggleOther() {
      showHide='visible';
      theText = '';
      if(document.myForm.WarrenBldg.style.visibility == 'visible'){
        showHide = 'hidden';
        theText = 'East';
      }
    
      document.myForm.WarrenBldg.style.visibility = showHide;
      document.myForm.WarrenBldg.value = theText;
    }
    Call it with something with

    onclick="toggleOther()"

    Eric

  • #3
    Regular Coder
    Join Date
    Jul 2003
    Posts
    601
    Thanks
    17
    Thanked 0 Times in 0 Posts
    got it .. thanks.


  •  

    Posting Permissions

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