javascript tutorial - [Solved-5 Solutions] Radio button is selected via jQuery - javascript - java script - javascript array
Problem:
We have two radio buttons and want to post the value of the selected one. How to get the value with jQuery?
Solution 1:
To get the value of the selected radioName
item of a form with id myForm
:
Here's an example:
Solution 2:
Use this..
Solution 3:
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.:
Solution 4:
This should work:
Solution 5:
We can use the :checked selector along with the radio selector.