How to enable / disable text field when pressing radio button using javascript?

I have a radio button with a text box. How to enable / disable textbox using onclick switch event? That is, if the radio button is selected, the text field must be enabled or disabled.

Here is my code below:

<INPUT TYPE="radio" name="type" id="type1">
<input type="text" name="name" value="<?php echo $name?>" onChange="javascript:enableField();"/>
+3
source share
1 answer
<input type="radio" name="type" id="type1" onclick="toggleTextbox(this);" />
<input type="text" name="name" value="<?php echo $name?>" id="name1" />

<script type="text/javascript">
function toggleTextbox(rdo) {
    document.getElementById("name1").disabled = !rdo.checked;
}
</script>
+3
source

Source: https://habr.com/ru/post/1733143/


All Articles