I have two radio buttons and want to post the value of the selected one. How can I get the value with jQuery?
I can get all of them like this:
$("form :radio")
How do I know which one is selected?
I have two radio buttons and want to post the value of the selected one. How can I get the value with jQuery?
I can get all of them like this:
$("form :radio")
How do I know which one is selected?
To get the value of the selected radio that uses a class:
I wrote a jQuery plugin for setting and getting radio-button values. It also respects the "change" event on them.
Put the code anywhere to enable the addin. Then enjoy! It just overrides the default val function without breaking anything.
You can visit this jsFiddle to try it in action, and see how it works.
Fiddle
In my case I have two radio buttons in one form and I wanted to know the status of each button. This below worked for me:
If you want just the boolean value, i.e. if it's checked or not try this:
Get all radios:
Filter to get the one thats checked
If you have Multiple radio buttons in single form then
This is working for me.