Radio inputs created with a loop in jQuery all being assigned the same value

First time posting here. I am trying to make a movie recommender that presents the user with a set of movies to rate on a radio scale of 1-10 with a "No Rating" button if they haven’t seen the movie. I have been trying to loop over all of the checked buttons to get their values, but they are all coming up as the value assigned to the first "No Rating" button in the radio input, which is appended to the table before the inner loop executes. Can anyone shed some light on what’s going on? I don’t have much experience in JS or jQuery and have had my brother helping me along the way. Here is my code:

for (let i = 0; i<keys.length; i++) {
...
    let $movieRating = $('<tr class="rating-row">')
...
// Add initial "No Rating" button
    let $ratingButton = $('<td>');
    $ratingButton.append($(`<input type="radio" class="ratButton" id="rating${i}-0"
      name="rating${i}" value=null><label for="rating${i}-0">No Rating</label>`));
// Add 1-10 buttons   
    for (let j=1; j <= 10; j++) {
        $ratingButton.append($(`<input type="radio" class="ratButton" id="rating${i}-${j}"
          name="rating${i}" value="${j}"><label for="rating${i}-${j}">${j}</label>`));
    }
    $movieRating.append($ratingButton);
    $("table tbody").append($movieRating);

I have the value set to null for the "No Rating" button, and then the 1-10 buttons are supposed to have the value set to the ${j}. I am pulling the values with:

$('.rating-row').each(function(idx, row) {
    let $radioButton = $(row).find('input:radio');
    if ($radioButton.is(':checked')) {
        let radioVal = $radioButton.val();
         console.log(radioVal);
    }
})

radioVal is always coming up null, no matter what is checked. I hope this is clear. Tips on formatting welcome as well. Thanks a lot!

156 thoughts on “Radio inputs created with a loop in jQuery all being assigned the same value”

  1. Thanks for another great article. Where else may just anybody get that type of info in such an ideal manner of writing?
    I have a presentation subsequent week, and I’m at the
    search for such information.

    Reply
  2. hello there and thank you for your information – I have certainly picked up anything new from right
    here. I did however expertise some technical points using this
    website, as I experienced to reload the site a lot of times previous
    to I could get it to load properly. I had been wondering if your web hosting is OK?
    Not that I am complaining, but slow loading instances times will often affect your placement
    in google and can damage your high quality score if ads and marketing
    with Adwords. Well I’m adding this RSS to my email and can look
    out for a lot more of your respective interesting content.

    Ensure that you update this again very soon.

    Reply
  3. Every weekend i used to go to see this web site, for the reason that
    i wish for enjoyment, for the reason that
    this this web page conations genuinely pleasant funny stuff too.

    Reply
  4. Hello there, I found your web site by means of Google while
    searching for a related subject, your site came up, it
    seems great. I have bookmarked it in my google bookmarks.

    Hello there, simply turned into aware of your blog via Google, and located that it is really informative.
    I’m going to be careful for brussels. I’ll be grateful for those who proceed this
    in future. A lot of people will likely be benefited out of your
    writing. Cheers!

    Reply
  5. I am really impressed with your writing skills and also with
    the layout on your weblog. Is this a paid theme or did you
    customize it yourself? Either way keep up the excellent quality writing, it is
    rare to see a nice blog like this one these days.

    Reply
  6. Nice post. I was checking constantly this blog and I’m inspired!
    Extremely useful information specially the ultimate part 🙂
    I maintain such information a lot. I was
    seeking this certain information for a long time. Thank you and best
    of luck. ps4 games https://bitly.com/3z5HwTp ps4 games

    Reply
  7. Heya i’m for the primary time here. I came across this board and I in finding It really useful & it helped me out much.
    I’m hoping to provide one thing back and aid others
    such as you helped me.

    Reply
  8. I’ve been browsing on-line more than 3 hours lately,
    yet I by no means found any interesting article like yours.
    It’s beautiful worth enough for me. In my view, if all website owners and bloggers
    made good content material as you did, the internet can be much more
    useful than ever before.

    Reply

Leave a Comment