We have two radio buttons and want to post the value of the selected one. How to get the value with jQuery?
To get the value of the selected
radioName item of a form with id
Here's an example:
If we already have a reference to a radio button group, for example:
Use the filter() function, not find(). (find() is for locating child/descendant elements, whereas filter() searches top-level elements in your selection.)
Note: This answer was originally correcting another answer that recommended using find(), which seems to have since been changed. find() could still be useful in the situation where we already had a reference to a container element, but not to the radio buttons, e.g.:
This should work:
We can use the :checked selector along with the radio selector.