I have some radio buttons on my page that pop up for users to flag things (below). Along with the radio buttons is an "other" button with a textarea to write in a different reason. I would like to be able to see which buttons are pressed when the form is submitted via jquery. I know how to use .post() but im not sure if should i use .val() on each id of the radio buttons. Or, is there one check that can check the entire group and get the checked label? Im pretty sure i can use .val() on the textarea if the other button is pressed.
HTML:
<input type='radio' id='spam' name='flagGroup'></input><label for='spam'>It is spam</label><br>
<input type='radio' id='offTopic' name='flagGroup'></input><label for='offTopic'>It is off topic</label><br>
<input type='radio' id='quality' name='flagGroup'></input><label for='quality'>It does not meet quality standards</label><br>
<input type='radio' id='wrongLocation' name='flagGroup'></input><label for='wrongLocation'>It is in the wrong location</label><br>
<input type='radio' id='duplicate' name='flagGroup'></input><label for='duplicate'>There is a duplicate question</label><br>
<input type='radio' id='other' name='flagGroup'></input><label for='other'>Other:</label><br>
<textarea id='flagOtherTextarea' rows='2' cols='40' wrap='soft'></textarea>
<hr />
<input type='radio' id='mod'></input><label for='mod'>It needs moderator attention</label>
Try the following selector
$allChecked = $('input[type="radio"]:checked');
If you wanted to get the text of all of the labels after the input you could do the following
$('input[type="radio"]:checked').each(function() {
var label = $(this).next('label');
alert(label.text());
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With