Enable Textbox when radio button selected

Discussion in 'Javascript' started by teddy.am@gmail.com, Jun 10, 2006.

  1. Guest

    Guys,

    I have a set of 6 radio buttons, infront of each one there's a textbox
    ....
    i need all textboxes disabled .... once one of the radio buttons is
    selected, the texbox infront of it will be anabled to type in ...

    any fast solution?
    , Jun 10, 2006
    #1
    1. Advertising

  2. writes:

    > I have a set of 6 radio buttons, infront of each one there's a textbox
    > ...
    > i need all textboxes disabled .... once one of the radio buttons is
    > selected, the texbox infront of it will be anabled to type in ...


    ----
    <script type="text/javascript">
    var currentEnabled = null;
    function enableElement(elem) {
    if (currentEnabled) {
    currentEnabled.disabled = true;
    }
    elem.disabled = false;
    currentEnabled = elem;
    }
    </script>
    <form action="">
    <input type="text" name="inp1" disabled="disabled">
    <input type="radio" name="sel" value="1"
    onclick="enableElement(this.form.elements['inp1']);">
    <br>
    <input type="text" name="inp2" disabled="disabled">
    <input type="radio" name="sel" value="2"
    onclick="enableElement(this.form.elements['inp2']);">
    <br>
    <input type="text" name="inp3" disabled="disabled">
    <input type="radio" name="sel" value="3"
    onclick="enableElement(this.form.elements['inp3']);">
    </form>
    ----

    You might want to have the textboxes enabled by default and use
    a script to disable them. Then they still work if Javascript is
    disabled.

    Good luck.
    /L
    --
    Lasse Reichstein Nielsen -
    DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
    'Faith without judgement merely degrades the spirit divine.'
    Lasse Reichstein Nielsen, Jun 10, 2006
    #2
    1. Advertising

  3. Guest

    Thumbs up,
    Thanks a bunch


    Lasse Reichstein Nielsen wrote:
    > writes:
    >
    > > I have a set of 6 radio buttons, infront of each one there's a textbox
    > > ...
    > > i need all textboxes disabled .... once one of the radio buttons is
    > > selected, the texbox infront of it will be anabled to type in ...

    >
    > ----
    > <script type="text/javascript">
    > var currentEnabled = null;
    > function enableElement(elem) {
    > if (currentEnabled) {
    > currentEnabled.disabled = true;
    > }
    > elem.disabled = false;
    > currentEnabled = elem;
    > }
    > </script>
    > <form action="">
    > <input type="text" name="inp1" disabled="disabled">
    > <input type="radio" name="sel" value="1"
    > onclick="enableElement(this.form.elements['inp1']);">
    > <br>
    > <input type="text" name="inp2" disabled="disabled">
    > <input type="radio" name="sel" value="2"
    > onclick="enableElement(this.form.elements['inp2']);">
    > <br>
    > <input type="text" name="inp3" disabled="disabled">
    > <input type="radio" name="sel" value="3"
    > onclick="enableElement(this.form.elements['inp3']);">
    > </form>
    > ----
    >
    > You might want to have the textboxes enabled by default and use
    > a script to disable them. Then they still work if Javascript is
    > disabled.
    >
    > Good luck.
    > /L
    > --
    > Lasse Reichstein Nielsen -
    > DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
    > 'Faith without judgement merely degrades the spirit divine.'
    , Jun 10, 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. xazos79
    Replies:
    2
    Views:
    6,063
    xazos79
    Mar 1, 2006
  2. steve smith
    Replies:
    0
    Views:
    4,563
    steve smith
    Jul 4, 2003
  3. Scott D Johnson
    Replies:
    1
    Views:
    1,049
    Scott D Johnson
    Sep 27, 2006
  4. Hiten
    Replies:
    1
    Views:
    611
    Vidar Petursson
    May 26, 2004
  5. Marc
    Replies:
    9
    Views:
    200
Loading...

Share This Page