Roland Roland - 1 year ago 68
jQuery Question

Using JQuery to check if no radio button in a group has been checked

I'm sitting with a problem, I need to check with JQuery if no radio button within a radio button group has been checked, so that I can give the users an javascript error if they forgot to check a option.

I'm using the following code to get the values

var radio_button_val = $("input[name='html_elements']:checked").val();

Answer Source
if (!$("input[name='html_elements']:checked").val()) {
   alert('Nothing is checked!');
else {
  alert('One of the radio buttons is checked!');