3

I use js like below to prevent click on some radio button.

It's work totally fine in Chrome.

But on IE8 It's still can't check but default value was disappear when click other radio in group.

 $("body").on("change", ".readonly", function () {
    return false;
});

How can i make radio readonly and also work on IE8?

2
  • doesn't the attribute "disabled" do what you want to do?
    – TheBalco
    Jun 30, 2015 at 8:34
  • I still want data to be submit to server. and if I use disable with hidden field. I have to edit many page. So I try to find another way.
    – LLF
    Jun 30, 2015 at 8:36

1 Answer 1

4

<input type="radio" readonly /> does not work, but using click does partly work. If you have two radios with the same name, IE will however still uncheck the checked one regardless with this code

$("body").on("click", ".readonly", function(e) {
  e.preventDefault();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<input name="rad" type="radio" class="readonly" />
<input name="rad" type="radio" checked class="readonly" />


Here is a solution: https://stackoverflow.com/a/5437904/295783

$(function() {
  $(':radio:not(:checked)').attr('disabled', true);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<input name="rad" type="radio" class="readonly" />
<input name="rad" type="radio" checked class="readonly" />

2
  • It's does not work if you have two radio and one of them alreaady checked. The one that checked will be uncheck.
    – LLF
    Jun 30, 2015 at 8:31
  • 2
    Thank you for solution. Disabled not checked one is work really good.
    – LLF
    Jun 30, 2015 at 9:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.