rojobo rojobo - 3 months ago 18
Vb.net Question

Default Radio button not visually checked

I'm building a dynamic list of

RadioButton
inside a
For
loop
using

<%= Html.RadioButtonFor(m => m.Gender, m.Value) %>


The dynamic list gets created alright but the first
RadioButton
is NOT VISUALLY checked

What I mean by this is that the circle portion of the
RadioButton
is not filled with the black dot that tells you it's checked.

However, when I inspect the HTML in the browser's dev tools, the attribute checked="checked" is set!

I tried doing a JQUERY onload

$("#yada").attr("checked", "checked");

$("#yada").click();


and NOTHING works!!! The inspector still says the element checked: true but still the little circle does not get the black dot in it UNLESS I manually click it.

I've also tried setting the first radio button like

Html.RadioButtonFor(m=> m.Gender, m.Value, new { checked = "checked"})

Answer

Just to give an answer to this question for anyone who encounters a similar issue (without reading the comments):

If you manually set checked to multiple elements in the same radio button group (defined by the name attribute), only the last one will be displayed as checked, but once you click on one manually, it will reset all the checked elements to match your latest selection. See this fiddle (https://jsfiddle.net/0ekaznbb/) for an example.