using javascript with radio button to disable a text box - does not work in IE

Discussion in 'Javascript' started by s.chelliah@gmail.com, Aug 29, 2006.

  1. Guest

    Hi,
    I am trying to use javascript, div tag and radio button to
    disable/enable a text box. It works fine
    in netscape and firefox, but in IE, the text box is not disabled when
    the user checks the radio button.

    Note that I am using two div statements. Any other solutions also
    wellcome.

    <html>
    <title>Test</title>

    <head>
    <script type="text/javascript">

    function checkButton(rName) {

    collection = document.all[rName];
    if (collection[1].checked)
    {
    //document.myform.abutton.disabled = true;
    document.getElementById("durfixed").style.display="block";
    document.getElementById("nodurfixed").style.display="none";
    }
    else
    {
    document.getElementById("durfixed").style.display="none";
    document.getElementById("nodurfixed").style.display="block";
    }

    }
    </script>
    </head>

    <body >


    <h2>Radio Button Check</h2>

    <form name=myform>
    <fieldset style="width:100px">
    <legend>Toggle</legend>
    <INPUT type=radio name=milestone value="Beta1"
    onChange="checkButton('milestone')">Beta 1<br>
    <INPUT type=radio name=milestone checked value="Beta2"
    onChange="checkButton('milestone')">Beta 2<br>
    </fieldset>

    <br>

    <div id="durfixed" style="display:block;" >
    <input type=text name=ename value="">
    </div>
    <div id="nodurfixed" style="display:none;" >
    <input type=text name=noename readonly value="" style="background:
    #cccccc" >
    </div>


    </body>
    </form>
    </html>


    Thanks for the help
    Siva
     
    , Aug 29, 2006
    #1
    1. Advertising

  2. RobG Guest

    wrote:
    > Hi,
    > I am trying to use javascript, div tag and radio button to
    > disable/enable a text box. It works fine
    > in netscape and firefox, but in IE, the text box is not disabled when
    > the user checks the radio button.


    First, the solution: change your onchange to onclick.

    Second, why. Your function is working in IE too. The difference is
    tha in IE, the onchange event fires when the control loses focus (which
    is as per the W3C spec) whereas other browsers fire a radio button's
    onchange essentially as an onclick.

    By using onclick, you'll get consistent behaviour across browsers.
    Note however that using reload, it is possible to have the state of the
    text input out of sync with the radio button selection in some (most?)
    browsers. onload you should either run checkButton() or reset the form
    to a known state.


    --
    Rob
     
    RobG, Aug 30, 2006
    #2
    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. Hiten
    Replies:
    1
    Views:
    624
    Vidar Petursson
    May 26, 2004
  2. Marcus
    Replies:
    4
    Views:
    401
    Marcus
    Feb 22, 2012
  3. Jim

    Check box and text box disable

    Jim, Jun 3, 2004, in forum: Javascript
    Replies:
    3
    Views:
    122
    Randy Webb
    Jun 4, 2004
  4. Marc
    Replies:
    9
    Views:
    213
  5. sam
    Replies:
    5
    Views:
    237
Loading...

Share This Page