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?

LLF
  • 668
  • 3
  • 10
  • 27
  • doesn't the attribute "disabled" do what you want to do? – TheBalco Jun 30 '15 at 08: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 '15 at 08:36

1 Answers1

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" />
mplungjan
  • 169,008
  • 28
  • 173
  • 236
  • 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 '15 at 08:31
  • 2
    Thank you for solution. Disabled not checked one is work really good. – LLF Jun 30 '15 at 09:30