Disable radio button originally javascript

I am trying to set a switch that first turns off using javascript. Here is my code. HTML:

document.getElementById("authorise1_radio").disabled = true;
document.getElementById("authorise2_radio").disabled = true;
<input checked class="radio_input" id="authorise1_radio" name="authorise1_radio" type="radio" value="authorise">
<label class="radio_label" for="authorise1_radio">Yes</label>

<input class="radio_input" id="authorise2_radio" name="authorise2_radio" type="radio" value="authorise">
<label class="radio_label" for="authorise2_radio">No</label>
Run codeHide result

I tried the same code at w3school.com and it works great. This is the code:

    document.getElementById("myRadio").disabled = true;
Radio Button:
<input type="radio" id="myRadio">
Run codeHide result
+4
source share
5 answers

Try the following: you can use javascript code below the switch html code. for example: (then it can work)

<input checked class="radio_input" id="authorise1_radio" name="authorise_radio" type="radio" value="authorise">
<label class="radio_label" for="authorise1_radio">Yes</label>

<input class="radio_input" id="authorise2_radio" name="authorise_radio" type="radio" value="authorise">
<label class="radio_label" for="authorise2_radio">No</label>
<script>
document.getElementById("authorise1_radio").disabled = true;
document.getElementById("authorise2_radio").disabled = true;
</script>
+1
source

Just put the script between the tags <head>in your html

<head>
<script>
    document.getElementById("radioButton").disabled = true;
 </script>
</head>
0
source

, .

document.getElementById("myRadio").readonly = true;

, .

0

onclick

<body>
<script type="text/javascript">
var checked = 0;
function change() {
    if (checked === 0) {
        checked++;
    }else {
        document.getElementById("myRadioID").checked = false;
        checked = 0;
    }
}
</script>
Radio Button:
<input type="radio" id="myRadioID" onclick="javascript:change();"/>
</body>
0

,

<script>
     document.getElementById("authorise1_radio").disabled = true;
</script>
-1

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


All Articles