I'm trying to set the radio button to disable initially with 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>
I tried the same code in w3school.com and it works fine. This is the code there:
document.getElementById("myRadio").disabled = true;
Radio Button: <input type="radio" id="myRadio">
Try this: you can use javascript code below of html code of radio button. like following: (then it may works)
<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>
Just put the script between the <head>
tags in your html
<head>
<script>
document.getElementById("radioButton").disabled = true;
</script>
</head>
It seems like there's nothing wrong with your code.
try using
document.getElementById("myRadio").readonly = true;
I guess that would do the trick.
Onclick change State
<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>
Please put this below code in footer section
<script>
document.getElementById("authorise1_radio").disabled = true;
</script>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.