Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery After page loaded, check if radio button selected

I can easily grab the value or check if a radio button is selected using the .click(function() but what I need to do if check to see if a radio button is selected and/ or grab its value after a page has loaded (i.e. some radio buttons are pre-selected on page load).

I assumed something like this might work but it doesn't:

$("input[type=radio][name=q22]:checked").val()

Any suggestions?

like image 935
Homer_J Avatar asked Sep 07 '13 07:09

Homer_J


People also ask

How can I check if a radio button is selected?

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.

How can I know which radio button is selected via jQuery?

To check which radio button is selected in a form, we first get the desired input group with the type of input as an option and then the value of this selection can then be accessed by the val() method. This returns the name of the option that is currently selected.

How can get radio button value onload in jQuery?

And you wanted to check the one with a value of "Male" onload if no radio is checked: $(function() { var $radios = $('input:radio[name=gender]'); if($radios.is(':checked') === false) { $radios. filter('[value=Male]'). prop('checked', true); } });

How check radio box is checked or not in jQuery?

$('#rdSelect:checked'). val() method returns "on" when radio button is checked and "undefined", when radio button is unchecked. var isChecked = $('#rdSelect').is(':checked'); The above method uses "is" selector and it returns true and false based on radio button status.


1 Answers

Try with:

$(document).ready(function(){
    $("input[type=radio][name='q22']:checked").val()
});
like image 56
Daniele Avatar answered Dec 14 '22 05:12

Daniele