3

can anyone tell me how can I make a checkbox readonly instead of disabled? For a textbox, I am using it like this

@Html.TextBoxFor(m => m.FirstName, new { id = "fName", @readonly="readonly" })

Now, I have a checkbox and a radiobutton like this

@Html.CheckBoxFor(m => m.Iseighteen, new { id = "18", @disabled = "disabled" })
@Html.RadioButtonFor(m => m.isMale, new { id = "male",@disabled = "disabled" })

The problem with the disabled is that I can't get focus in the disabled field while I can get a focus in the read only. If I tab then it selects the readonly fields so that the screen reader can read it but if its disabled then it skips everything disabled and goes to the footer. I tried using readonly for checkbox and radio but it doesn't work and lets the user edit. So, any suggestions on that?

tereško
  • 58,060
  • 25
  • 98
  • 150
123456 hello
  • 47
  • 2
  • 5
  • I would think that your read only attempt should work according to this http://stackoverflow.com/questions/8761647/how-to-create-readonly-textbox-in-asp-net-mvc3-razor good luck. – Trevor Sep 26 '13 at 22:56
  • Radio buttons can't be ReadOnly ...This post help you http://stackoverflow.com/questions/1953017/why-cant-radio-buttons-be-readonly – Ajinder Singh Sep 27 '13 at 07:45

2 Answers2

5

You can user the below Code to restrict users from selecting Checkbox and radiobutton ...

  $(':radio,:checkbox').click(function(){
return false;
   });

Hope this helps you.

Ajinder Singh
  • 532
  • 2
  • 8
4

Try using

@Html.CheckBoxFor(model => model.IsActive, new { onclick = "return false" })

Hope it will work more easy way.

Ananda G
  • 2,389
  • 23
  • 39