If I have the following jQuery mobile html;
<fieldset data-role="controlgroup" data-type="horizontal" name="Smoker" id="Smoker">
<input name="radio3" id="radio3" value="Yes" type="radio" />
<label for="radio3">Yes</label>
<input name="radiobuttons1" id="radio4" value="No" type="radio" />
<label for="radio4">No</label>
</fieldset>
I thought I could do this in jQuery;
$("#Smoker").val()
However this yields no result. Do I in fact need to query both the inputs to see which one has been checked or is there a nice jQuery Mobile way to do this?
try
$("#Smoker :radio:checked").val();
First your radio buttons should have the same name attribute, otherwise selecting one doesn't deselct the other, so instead of your current markup you should have something like the following
<fieldset data-role="controlgroup" data-type="horizontal" name="Smoker" id="Smoker">
<input name="smokerRdo" id="radio3" value="Yes" type="radio" />
<label for="radio3">Yes</label>
<input name="smokerRdo" id="radio4" value="No" type="radio" />
<label for="radio4">No</label>
</fieldset>
AS for getting the value it's the same as regular jQuery, however your trying to get the value of the fieldset, not the radio group, instead try
$('input[name=smokerRdo]:checked').val()
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