showing a textbox if criteria is met

Discussion in 'HTML' started by chris, Aug 21, 2004.

  1. chris

    chris Guest

    i have a set od radio buttons what i wanty to do is when one particular
    button is selected bring up an additional text box for additional
    information

    how would i do this
     
    chris, Aug 21, 2004
    #1
    1. Advertising

  2. chris

    Will Gittoes Guest

    chris wrote:
    > i have a set od radio buttons what i wanty to do is when one particular
    > button is selected bring up an additional text box for additional
    > information
    >
    > how would i do this
    >
    >
    >


    <html>
    <head>
    <script>
    function ShowTextBox(){

    Text_b_1 = document.getElementById("TextBoxOne");
    Text_b_1.style.display="block"

    }
    </script>
    </head>
    <body>

    <form name="form1">
    <input type="button" onClick="ShowTextBox()">
    <input type="text" name="textbox1" value="" id="TextBox1"
    style="display:none">
    </form>


    </body>
    </html>


    Modify as you need. Just call the ShowTextBox to make the textbox (with
    name textbox1 and id TextBox1) appear.

    Make Text_b_1.style.display="none" to make it disappear again.
     
    Will Gittoes, Aug 21, 2004
    #2
    1. Advertising

  3. On Sat, 21 Aug 2004 23:25:47 +1200, Will Gittoes <>
    wrote:

    [snip]

    > <script>


    Valid HTML requires the type attribute.

    <script type="text/javascript">

    > function ShowTextBox(){
    >
    > Text_b_1 = document.getElementById("TextBoxOne");


    You should declare that variable using the var keyword to prevent it from
    becoming global. It's also preferable to access form controls through the
    containing form (if it exists) as that is likely to work across more
    browsers.

    var elem = document.forms['formName'].elements['controlName'];

    > Text_b_1.style.display="block"


    The style element should be tested before it's used to prevent unnecessary
    errors. Furthermore, INPUT is an inline-, not block-level, element.

    if(elem.style) {
    elem.style.display = 'inline';
    }

    However, as the control should be visible by default (see below), simply
    assigning an empty string ('') will be sufficient.

    [snip]

    > <input type="text" name="textbox1" value="" id="TextBox1"
    > style="display:none">


    As Martin said in his post, that is a bad idea. If scripting is not
    available, or the browser doesn't support the manipulation of inline
    styles, the page becomes unusable. The textbox should only be hidden by a
    script, as only a script can show it again.

    [snip]

    Mike

    --
    Michael Winter
    Replace ".invalid" with ".uk" to reply by e-mail.
     
    Michael Winter, Aug 21, 2004
    #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. Simon Harvey
    Replies:
    2
    Views:
    509
    Simon Harvey
    Feb 27, 2004
  2. DotNetJunkies User
    Replies:
    1
    Views:
    374
    Teemu Keiski
    May 1, 2004
  3. Jay Ge
    Replies:
    1
    Views:
    331
    Jeff Dillon
    Nov 10, 2004
  4. Gerald

    External exe call from asp.met

    Gerald, Dec 9, 2005, in forum: ASP .Net
    Replies:
    6
    Views:
    1,746
    Willy Denoyette [MVP]
    Dec 9, 2005
  5. chris

    showing a textbox if criteria is met

    chris, Aug 21, 2004, in forum: Javascript
    Replies:
    3
    Views:
    90
    Michael Winter
    Aug 21, 2004
Loading...

Share This Page