#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    85
    Rep Power
    0

    Get value of checked radio buttons


    Hello,
    I have a script that outputs the html for the radio buttons like this:

    <input type="radio" value="1" name="elegirparadalist" class="elegirparadalist">
    <input type="radio" value="2" name="elegirparadalist" class="elegirparadalist">
    <input type="radio" value="3" name="elegirparadalist" class="elegirparadalist">
    <input type="radio" value="4" name="elegirparadalist" class="elegirparadalist">

    I need to get the value of checked radio button, however below script only works when I select the first radio button:

    <script>
    var element2 = document.querySelector('input[name="elegirparadalist"]');
    element2.addEventListener('click', () => {
    console.log(document.querySelector('input[name="elegirparadalist"]').value)
    })
    </script>

    Any help please, thanks
  2. #2
  3. Headless Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,966
    Rep Power
    9647

IMN logo majestic logo threadwatch logo seochat tools logo