SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    Phil fillup07's Avatar
    Join Date
    May 2002
    Location
    Jacksonville, FL
    Posts
    1,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How do I do this??

    I have a bunch of Drop Down Lists that looks like this:

    Code:
    <select size='1' name='GAGETYPE' onChange="show('invisibleGAGETYPE', this.options[this.selectedIndex].firstChild.nodeValue)">
      <option selected>First Option</option>
      <option>Second</option>
      <option>Third</option>
      <option>Other</option>
    </select>
    
    <span id='invisibleGAGETYPE'>
      <input type='text' name='GAGETYPEother'>
    </span>
    The javascript function is this:
    Code:
    function show(el, txt){
    var elem = document.getElementById(el);
    elem.style.visibility = (txt == 'Other') ? 'visible' : 'hidden';
    }
    And the CSS is this:
    Code:
    <style>
    #invisibleGAGETYPE {visibility: hidden;} 
    </style>
    It works great. Here's what it does:
    The text box is hidden.
    If the default option is not "Other",
    whenever you change the option in the drop down list to "Other",
    the Text Box appears.

    When you change it off of "Other",
    the text box dissapears again.

    That's great - but I also need it so that if the default
    field *is* "Other" that the text box will default to be Visible, but if the drop down list is changed to something
    besides Other, it will become invisible.

    I tried something like:
    Code:
    <select size='1' name='GAGETYPE' onChange="show('invisibleGAGETYPE', this.options[this.selectedIndex].firstChild.nodeValue)" onLoad="show('invisibleGAGETYPE', this.options[this.selectedIndex].firstChild.nodeValue)">
    But of course it didn't work.

    Anyone?

    Thanks a lot.

  2. #2
    Sultan of Ping jofa's Avatar
    Join Date
    Mar 2002
    Location
    SvÝ■jˇ­
    Posts
    4,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The only elements that can have an onload attribute are body and frameset...

    Write a new function (to call on body.onload) that gets the selected value from GAGETYPE and then calls show()

  3. #3
    Phil fillup07's Avatar
    Join Date
    May 2002
    Location
    Jacksonville, FL
    Posts
    1,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK... I thought of a different way to do it and it seems to work. I just didn't give the Drop Down Lists whose value is Other the invisible property. It still hides the text box if the Option is changed from other

    Thanks
    If you think there's a better way, let me know.


Bookmarks

Posting Permissions

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