[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 285
  • Last Modified:

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

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.
0
code_talker
Asked:
code_talker
2 Solutions
 
Ray PaseurCommented:
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.
0
 
nap0leonCommented:

<script>
function EnableDisable(input,action) {
  if (action=="enable"){
    document.getElementById(input).disabled=false;
  } else {
    document.getElementById(input).disabled=true;
  }
}
</script>
<body>

<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"/>

</body>

Open in new window

0
 
Mohamed AbowardaSoftware EngineerCommented:
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.
0
 
code_talkerAuthor Commented:
250
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now