I used Bootstrap to create the radio buttons:
<div id="heightForm">
<legend class="h">
Height:
<div class="form-check form-check-inline weightChoose commonRadio">
<div class="form-check form-check-inline kg">
<input class="form-check-input" type="radio" name="heightButtonS" role="radio" value="METER" id="h1"/>
<label class="form-check-label lbl" for="h1">Meter</label>
</div>
<div class="form-check form-check-inline pound">
<input class="form-check-input" type="radio" name="heightButtonS" role="radio" value="FEET" id="h2"/>
<label class="form-check-label lbl" for="h2">Feet</label>
</div>
</div>
</legend>
</div>
i wanted to console.log(heightIn);
where
var heightIn = $('input[name="heightButtonS"]:checked').val();
but it gives undefined.
i also tried:
var heightIn = $('input[name=heightButtonS]:checked').val();
var heightIn = $('input[name="heightButtonS"]:checked').value();
This does return the value when there is an attribute "checked" in one of the buttons. Even on selecting the other button it returns the value of that assigned button. I want it to retrieve value for the button which is selected.
Does this not work anymore?
undefinedwhen$('input[name="heightButtonS"]:checked').length === 0- ie before the user has selected one of the radios (as noted above, just adding the.lengthconfirmation)