Why can't radio buttons be “readonly”?

前端 未结 13 1254
误落风尘
误落风尘 2020-11-27 10:45

I would like to show a radio button, have its value submitted, but depending on the circumstances, have it not editable. Disabled doesn\'t work, because it doesn\'t submit t

13条回答
  •  再見小時候
    2020-11-27 11:09

    I found that use onclick='this.checked = false;' worked to a certain extent. A radio button that was clicked would not be selected. However, if there was a radio button that was already selected (e.g., a default value), that radio button would become unselected.

    
    N
    Y
    

    For this scenario, leaving the default value alone and disabling the other radio button(s) preserves the already selected radio button and prevents it from being unselected.

    
    N
    Y
    

    This solution is not the most elegant way of preventing the default value from being changed, but it will work whether or not javascript is enabled.

提交回复
热议问题