1

How can I retrieve the radio button which is selected in either JS or jQuery? I'm interested in the 'User-1' or User-2' value to be retrieved.

<div class="container">
    <h2 class="form-signin-heading">Existing Users</h2>
    <div class="input-group">
        <span class="input-group-addon">
            <input type="radio" name="radio" aria-label="...">
        </span>
        <label class="form-control" aria-label="...">User-1</label>
    </div>
    <div class="input-group">
        <span class="input-group-addon">
            <input type="radio" name="radio" aria-label="...">
        </span>
        <label class="form-control" aria-label="...">User-2</label>
    </div>
</div>
user5581557
  • 213
  • 4
  • 14
  • 1
    Possible duplicate of [Get Radio Button Value with Javascript](http://stackoverflow.com/questions/9618504/get-radio-button-value-with-javascript) – vidriduch Feb 26 '16 at 14:57

1 Answers1

1

i'll suggest you to add an ID on your HTML tags for an easier selection

<input type="radio" id="someUniqueID" name="radio" aria-label="...">

From there you could do $('#someUniqueID').val() or document.getElementById('someUniqueID').value

If you wont / can't add an ID, you could do $( "input:radio")[0].val() or document.getElementsByTagName('input')[0].value, please note that when you select multiples inputs, it'll give you an array of inputs.

Jorel Amthor
  • 1,264
  • 13
  • 38