Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    May 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Enable/thisable 2 radiobuttons with checkbox

    Hello,


    I want to be able to enable 2 radiobuttons of the same group by checking a checkbox and disable them when the box is unchecked.

    I've found numerous scripts for enableing and disableing textfields and entire forms but none for radiobuttons of the same group. The script I have now (also from this forum from JohnKrutsch) is:

    (simplified for the purpose of posting it here)
    -------------------------------------------------------------------

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>enable/disable radiobuttons</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <SCRIPT TYPE="text/javascript" LANGUAGE="javascript">

    function checkIt(toCheck,toEnable){
    a=toEnable.split(",");
    for(i=0;i<a.length;i++) document.form2[a[i]].disabled=!document.form2[toCheck].checked;
    }

    </script>
    </head>

    <body>

    Check the checkbox to enable the radiobuttons.
    <br>
    <form action="bla.php" method="post" enctype="multipart/form-data" name="form2">
    <br>
    <strong>Enable the buttons</strong> <input type="checkbox" name="cb" value="checkbox" onClick="checkIt('cb','tx,tf')">
    <br><br>

    <input type="radio" name="tx" disabled>
    <strong>Radio1 </strong><br>
    <input type="radio" name="tx" disabled>
    <strong>Radio2</strong><br>
    Textfield<input type="text" name="tf" disabled>
    </form>

    </body>
    </html>

    ---------------------------------------------------------------
    This works fine except for enableing or disableing the radiobuttons.

    Is there any way to get this script to work for buttons of the same group? Or does anyone have another solution?

    Thank you for reading this and a big thanks to all the people helping other people out .

    Peter.

  • #2
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,467
    Thanks
    3
    Thanked 495 Times in 482 Posts
    Vic

    God Loves You and will never love you less.

    http://www.vicsjavascripts.org/Home.htm

    If my post has been useful please donate to http://www.operationsmile.org.uk/

  • #3
    New to the CF scene
    Join Date
    May 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    That works

    Thanks a lot! Didn't try the first but the f40 script works for the radiobuttons.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •