problem making <select> invisible

Discussion in 'Javascript' started by mitch, Jun 24, 2006.

  1. mitch

    mitch Guest

    I have a <select> that's inside a <td> and I want to dynamically
    show and hide the select. If elem is set to the <select> and I do
    either of these:

    elem.style.visibility = "hidden";
    elem.style.display = "none";

    it works in Firefox, but not in IE. In IE the page doesn't change at
    all.

    However if I set elem to the outer <td> and then do those two
    statements, they both work just fine.

    Does anybody know how to temporarily hide just a <select>?

    Thanks.
     
    mitch, Jun 24, 2006
    #1
    1. Advertising

  2. mitch wrote:
    > I have a <select> that's inside a <td> and I want to dynamically
    > show and hide the select. If elem is set to the <select> and I do
    > either of these:
    >
    > elem.style.visibility = "hidden";
    > elem.style.display = "none";
    >
    > it works in Firefox, but not in IE. In IE the page doesn't change at
    > all.


    Make sure the problem is not elsewhere. The following two lines both work for me:
    <select
    onchange='this.style.visibility="hidden"'><option>foo</option><option>bar</option></select>
    <select onchange='this.style.display="none"'><option>foo</option><option>bar</option></select>

    > However if I set elem to the outer <td> and then do those two
    > statements, they both work just fine.
    >
    > Does anybody know how to temporarily hide just a <select>?



    You /could/ enclose each select in a div...
     
    Mitja Trampus, Jun 25, 2006
    #2
    1. Advertising

  3. mitch

    RobG Guest

    mitch wrote:
    > I have a <select> that's inside a <td> and I want to dynamically
    > show and hide the select. If elem is set to the <select> and I do
    > either of these:
    >
    > elem.style.visibility = "hidden";
    > elem.style.display = "none";
    >
    > it works in Firefox, but not in IE. In IE the page doesn't change at
    > all.
    >
    > However if I set elem to the outer <td> and then do those two
    > statements, they both work just fine.
    >
    > Does anybody know how to temporarily hide just a <select>?


    I agree with Mitja, it should work:

    <script type="text/javascript">
    function hideShow(id)
    {
    var es;
    if ( document.getElementById
    && (es = document.getElementById(id))
    && (es = es.style)){
    es.display = ('none' == es.display)? '' : 'none';
    }
    }
    </script>

    <input type="button" value="Hide/show select"
    onclick="hideShow('sel_A');">
    <select id="sel_A">
    <option>foo
    <option>bar
    </select>


    --
    Rob
     
    RobG, Jun 26, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Susan van Houen

    making webcontrols visible/invisible

    Susan van Houen, Jul 13, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    585
    Anatoly
    Jul 13, 2003
  2. Miguel Dias Moura
    Replies:
    1
    Views:
    6,073
  3. SP
    Replies:
    1
    Views:
    963
  4. Andy B
    Replies:
    5
    Views:
    628
    Andy B
    May 29, 2008
  5. R.G. Vervoort

    making select visible \ invisible

    R.G. Vervoort, Apr 12, 2004, in forum: Javascript
    Replies:
    1
    Views:
    131
    R.G. Vervoort
    Apr 12, 2004
Loading...

Share This Page