javascript - How to get the selected radio button label text using jQuery -
i have radio button on page
<div id="someid"> <label class="radio-inline"> <input name="x" type="radio" onchange="getselectedval();">yes</label> <label class="radio-inline"> <input name="x" type="radio" onchange="getselectedval();">no</label> </div>
on page load don't want set selection not using checked
property. in javascript function, how can value yes
or no
based on user selection @ runtime?
function getselectedval() { console.log($('#someid input:radio.........); }
i have seen similar questions unable find solution of issue.
remove onchange
inline handler html
. use on
bind events.
:checked
select checked
radio button. closest
select parent label
, text()
label associated radio button. e.g. yes
$('[name="x"]').on('change', function () { alert($('[name="x"]:checked').closest('label').text()); });
Comments
Post a Comment