How do I get the value of the selected radio-button and output it inside the value of the hidden input field "selectedquantity"?
<div class="quantityselect">
<input type="radio" id="quantity0" name="radiobutton" value="50">
<label for="quantity0">
</label>
<input type="radio" id="quantity1" name="radiobutton" value="100">
<label for="quantity1">
</label>
</div>
<input id="selectedquantity" type="hidden" name="quantity" value="">
To set the checked value in your hidden value, you could use the following code:
$('#selectedquantity').val($("[name='radiobutton']:checked").val());
Wrap it in a change
event, and it should look something like this:
$(document).ready(function () {
$("[name='radiobutton']").change(function() {
$('#selectedquantity').val($("[name='radiobutton']:checked").val());
});
});
You can see a demo here: https://jsfiddle.net/k5y9gyf3/3/
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments