How do you disable an input textfield dynamically when clicking on radio buttos in a form?

Posted on 2011-10-28
Last Modified: 2012-05-12
I'm using HTML, PHP and JavaScript to create an HTML webpage. When the user clicks on a specific radio button, I want to disable an input textfield. When the user clicks on another radio button, I want to enable the input textfield. How do I code this? The solution must dynamically enable and disable the radio button.
Question by:code_talker
    LVL 107

    Expert Comment

    by:Ray Paseur
    Do you want to disable a radio button or a text field?  

    Please give us a link to any web site that does what you want, thanks.
    LVL 18

    Accepted Solution


    function EnableDisable(input,action) {
      if (action=="enable"){
      } else {
    <input type="radio" name="group1" value="enable" onClick="javascript:EnableDisable('input1','enable');">Enable</input><br/>
    <input type="radio" name="group1" value="disable" onClick="javascript:EnableDisable('input1','disable');">Disable</input><br/>
    <input type="text" id="input1" value="somevalue"/>

    Open in new window

    LVL 12

    Assisted Solution

    by:Mohamed Abowarda
    To enable/disable any text field, you can use the following line:
    document.getElementById('textfieldName').disabled = false;

    Open in new window

    To handle radio button click event, use "onClick" event.

    Author Closing Comment


    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    Suggested Solutions

    Someone recently asked me about how to display a progress indicator on a page while an iframe is loading. And I remember when I first came across this myself. It was a bit tricky to get my head around, but really, it's very simple. The most impor…
    JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
    In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now