Enable Textbox when radio button selected

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

  1. teddy.am

    teddy.am 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?
     
    teddy.am, Jun 10, 2006
    #1
    1. Advertisements

  2. ----
    <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, Jun 10, 2006
    #2
    1. Advertisements

  3. teddy.am

    teddy.am Guest

    Thumbs up,
    Thanks a bunch

     
    teddy.am, Jun 10, 2006
    #3
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.