Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

jquery

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(); 
like image 610
Elitmiar Avatar asked Jan 15 '10 14:01

Elitmiar


People also ask

How do you check if radio button is checked or not in JavaScript?

Using Input Radio checked property: The Input Radio checked property is used to return the checked status of an Input Radio Button. Use document. getElementById('id'). checked method to check whether the element with selected id is check or not.

Which method is used to check that radio button is selected or not?

The querySelector() function is a DOM method of JavaScript. It uses the common name property of radio buttons inside it. This method is used as given below to check which radio button is selected.


1 Answers

if (!$("input[name='html_elements']:checked").val()) {    alert('Nothing is checked!'); } else {   alert('One of the radio buttons is checked!'); } 
like image 122
Dominic Rodger Avatar answered Oct 19 '22 02:10

Dominic Rodger