JavaScript - HIDE/DISPLAY text boxes

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • kaeli

    #16
    Re: JavaScript - HIDE/DISPLAY text boxes

    In article <opsfxb9nr2x13k vk@atlantis>, M.Winter@blueyo nder.co.invalid
    enlightened us with...[color=blue]
    >
    > Modifying the style object is equivalent to modifying the style attribute
    > for that element. As the properties here are the most specific, they
    > override any settings inherited from active stylesheets.
    >
    > Assuming that the stylesheet for the page doesn't hide the element in
    > question[1], setting display = 'none' will override the browser's default
    > value. Assigning display = '' deletes this inline style, so the browser
    > will use it's own default. Modern browsers will use table-row, whilst IE
    > uses block[2].
    >
    > In the code that you've shown, the "display: none" rule has been added
    > directly to the row. As I said above, using script does exactly the same
    > thing, so assigning an empty string to the display property will still
    > have the same effect. If it was part of a stylesheet, this would be rather
    > more complicated, but that situation should be avoided, anyway (again [1]).
    >
    > Does that help?
    >[/color]

    Not really. But it works.
    Hey, it's Friday. My brain's dead.

    Modified verion: I like this better. It's cleaner. And it works in the
    browsers I tested in.

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title> New Document </title>

    <script type='text/javascript'>
    //RETURNS THE STYLE OBJECT
    function getStyle(name)
    {
    var s=null;
    if (document.getEl ementById)
    {
    s = document.getEle mentById(name). style;
    }
    else if (document.all)
    {
    s = document.all[name].style;
    }
    else if (document.layer s)
    {
    s = document.layers[name];
    }
    return s;
    }

    //HANDLES THE CHANGE IN SELECT BOX
    function checkInput(valu e)
    {
    if (value=='credit ')
    {
    show('cc_number ');
    show('expdate') ;
    }
    else
    {
    hide('cc_number ');
    hide('expdate') ;
    }
    }

    //CHANGES THE DISPLAY PROPERTY OF ELEMENT 'ID' TO BLOCK
    function show(id)
    {
    var styleObj=getSty le(id);
    styleObj.displa y='';
    }

    //CHANGES THE DISPLAY PROPERTY OF ELEMENT 'ID' TO NONE
    function hide(id)
    {
    var styleObj=getSty le(id);
    styleObj.displa y='none';
    }
    </script>
    </head>

    <body>
    <form name="f1">
    <table border='1'>
    <tbody>
    <tr>
    <!-- this row has the options in it -->
    <td width='153' valign='top'>So lution:</td>
    <td width='503'>
    <select name='solution' onchange='check Input(this.opti ons
    [this.selectedIn dex].value)'>
    <option value='none' selected>Choose From List</option>
    <option value='replace' >Replacement GC</option>
    <option value='check'>C heck Refund</option>
    <option value='credit'> Credit to Credit Card</option>
    </select>
    </td>
    </tr>
    <tr id="cc_number" style="display: none">
    <!-- this row should only be displayed if a credit card is chosen from the
    list -->
    <td width='153' valign='top'>Cr edit Card Number</td>
    <td width='503'><te xtarea cols='25' rows='1' name='cc'></textarea></td>
    </tr>
    <tr id="expdate" style="display: none">
    <!-- this row should only be displayed if a credit card is chosen from the
    list -->
    <td width='153' valign='top'> Expiration Date</td>
    <td width='503'><in put type='text' name='exp'></td>
    </tr>
    <tr>
    <td width='153' valign='top'>&n bsp;</td>
    <td width='503'><in put type='submit' value='Send Message' name='Send'>
    </td>
    </tr>
    </tbody>
    </table>
    </form>

    </body>
    </html>


    --
    --
    ~kaeli~
    I love God.
    It's His fanclub that I can't stand.



    Comment

    • Michael Winter

      #17
      Re: JavaScript - HIDE/DISPLAY text boxes

      On Fri, 15 Oct 2004 14:56:06 -0500, kaeli <tiny_one@NOSPA M.comcast.net>
      wrote:
      [color=blue]
      > In article <opsfxb9nr2x13k vk@atlantis>, M.Winter@blueyo nder.co.invalid
      > enlightened us with...[/color]

      [snip]
      [color=blue][color=green]
      >> Does that help?[/color]
      >
      > Not really.[/color]

      Reading it again, it can see why. :(

      Sorry, it seemed a good explanation at the time.
      [color=blue]
      > But it works.[/color]

      Good. :)
      [color=blue]
      > Hey, it's Friday. My brain's dead.[/color]

      Don't worry. Mine's too.
      [color=blue]
      > Modified verion: I like this better. It's cleaner. And it works in the
      > browsers I tested in.[/color]

      I'm tempted to suggest a few minor optimisations, but I've already been
      (rightfully) accused of being pedantic today so I'll watch Battlestar
      Galactica instead. :)

      Mike


      Again, my apologies for my previous double-post. I blame Opera...

      --
      Michael Winter
      Replace ".invalid" with ".uk" to reply by e-mail.

      Comment

      • Michael Winter

        #18
        [OT] Re: JavaScript - HIDE/DISPLAY text boxes

        On Fri, 15 Oct 2004 14:56:47 -0500, kaeli <tiny_one@NOSPA M.comcast.net>
        wrote:

        [snip]
        [color=blue]
        > (thanks michael)[/color]

        I sign, Mike, for a reason. :P

        Michael's too formal.

        Mike

        --
        Michael Winter
        Replace ".invalid" with ".uk" to reply by e-mail.

        Comment

        • !lurk

          #19
          Re: JavaScript - HIDE/DISPLAY text boxes

          Agreed; this is too complicated.

          Just change the style display properties of your show/hide element
          onchange.

          Comment

          • dmiller23462

            #20
            Re: JavaScript - HIDE/DISPLAY text boxes

            UPDATE!!!! I've noticed that this only works "once" and then not
            again....I tried to clear out my cache and get rid of all temp files
            and then try again but no luck....The only time it worked again was
            when I saved a 2nd version of the file and then went to THAT file in
            the URL bar....Help?
            *****
            This is the code that is in my "<head>" section...
            <script type='text/javascript'>
            //RETURNS THE STYLE OBJECT
            function getStyle(name)
            {
            var s=null;
            if (document.getEl ementById)
            {
            s = document.getEle mentById(name). style;
            }
            else if (document.all)
            {
            s = document.all[name].style;
            }
            else if (document.layer s)
            {
            s = document.layers[name];
            }
            return s;
            }

            //HANDLES THE CHANGE IN SELECT BOX
            function checkInput(valu e)
            {
            if (value=='credit ')
            {
            show('cc_number ');
            show('expdate') ;
            }
            else
            {
            hide('cc_number ');
            hide('expdate') ;
            }
            }

            //CHANGES THE DISPLAY PROPERTY OF ELEMENT 'ID' TO BLOCK
            function show(id)
            {
            var styleObj=getSty le(id);
            /* IE doesn't support table-row, but not using table-row mucks up
            Mozilla/Netscape/Opera, so...*sigh*, we have to do this to work around
            it.
            table-row is CSS-2 or something. */
            if ((document.getE lementById && !document.all) || window.opera)
            styleObj.displa y='table-row';
            else
            styleObj.displa y='inline';
            }

            //CHANGES THE DISPLAY PROPERTY OF ELEMENT 'ID' TO NONE
            function hide(id)
            {
            var styleObj=getSty le(id);
            styleObj.displa y='none';
            }
            </script>
            </head>


            *****
            This is the code that is actually in the body of the code
            <tr>
            <!-- this row has the options in it -->
            <td width='153' valign='top'>So lution:</td>
            <td width='503'>
            <select name='solution' onchange='check Input(this.opti ons
            [this.selectedIn dex].value)'>
            <option value='none' selected>Choose From List</option>
            <option value='Replace' >Replacement GC</option>
            <option value='Check'>C heck Refund</option>
            <option value='Credit'> Credit to Credit Card</option>
            </select>
            </td>
            </tr>
            <tr id="cc_number" style="display: none">
            <!-- this row should only be displayed if a credit card is chosen
            from the list -->
            <td width='153' valign='top'>Cr edit Card Number</td>
            <td width='503'><in put type='text' name='ccnumber'
            size="20"></textarea></td>
            </tr>

            <!--<tr id="expdate" style="display: none">
            <!-- this row should only be displayed if a credit card is chosen
            from the list
            <td width='153' valign='top'> Expiration Date</td>
            <td width='503'><in put type='text' name='exp'></td>
            </tr>
            <tr>
            <td width='153' valign='top'>&n bsp;</td>
            <td width='503'><in put type='submit' value='Send Message'
            name='Send'>
            </td>
            </tr>-->

            <tr id="expdate" style="display: none">
            <!-- this row should only be displayed if a credit card is chosen from
            the list -->
            <td width='153' valign='top'> Expiration Date</td>
            <td width='503'>
            <select size='1' name='expmonth' >
            <option selected>Month</option>
            <option value='Jan'>Jan </option>
            <option value='Feb'>Feb </option>
            <option value='Mar'>Mar </option>
            <option value='Apr'>Apr </option>
            <option value='May'>May </option>
            <option value='Jun'>Jun </option>
            <option value='Jul'>Jul </option>
            <option value='Aug'>Aug </option>
            <option value='Sep'>Sep </option>
            <option value='Oct'>Oct </option>
            <option value='Nov'>Nov </option>
            <option value='Dec'>Dec </option>
            </select>
            <select size='1' name='expyear'>
            <option selected>Year</option>
            <option value='2004'>20 04</option>
            <option value='2005'>20 05</option>
            <option value='2006'>20 06</option>
            <option value='2007'>20 07</option>
            <option value='2008'>20 08</option>
            <option value='2009'>20 09</option>
            <option value='2010'>20 10</option>
            </select></td>
            </tr>

            Comment

            Working...