title: OnChange event is not being triggered when same radio button is selected for second time;
body: <p>I have a dynamic table that allows a user to view details on images they've uploaded. This includes the ability to either create a new album (and move upload to that album) or move an upload to another album they've previously created.</p>
  <p>I've done this using radio buttons inside a dropdown menu with a text box where each time a new album is created, a corresponding label and input element is appended to the dropdown list in abc sorted order.</p>
  <p><a href="https://i.stack.imgur.com/7dJZ3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7dJZ3.png" alt="Screenshot of GUI" /></a></p>
  <p>The issue is that when a freshly created album is appended, only the first upload move is possible. After that, when I wish to move a different upload to the same album, the message shows that upload is already in said album (when it's not).</p>
  <p>Here is the desired order of events:</p>
  <ol>
  <li>Create new album. Upload is moved to new album.</li>
  <li>Label and input elements for the new album are appended to the dropdown radio list.</li>
  <li>Move another upload to this same album.</li>
  </ol>
  <pre class="lang-php prettyprint-override"><code>&lt;script&gt;
      $(document).ready(function() {
          var csrfName = &quot;&lt;?= csrf_token(); ?&gt;&quot;; 
          var csrfHash = &quot;&lt;?= csrf_hash(); ?&gt;&quot;;
  
          $(document).on('change', 'input[name=album_radio]', function() {
              var album = $('.album-radio:checked').val();
              var viewkey = $(this).data('viewkey');
  
              $.ajax({
                  type: &quot;POST&quot;,
                  url: &quot;&lt;?= base_url(); ?&gt;/users/members/manage_uploads&quot;,
                  dataType: &quot;JSON&quot;,
                  data: {
                      [csrfName]: csrfHash,
                      &quot;album_name&quot;: album,
                      &quot;viewkey&quot;: viewkey,
                  },
                  headers: {
                      'X-Requested-With': 'XMLHttpRequest',
                  },
                  success: function(data) {
                      var res = data;
  
                      // Update CSRF hash
                      csrfName = res.csrfName;
                      csrfHash = res.csrfHash;
  
                      // Add new album name 
                      $('#'+viewkey).html(album);
  
                      viewkey = '';
  
                      alert(res.message);
                  }
              });
          });
  
          $('.new-album-button').on('click', function () {
              let viewkey = $(this).attr('data-viewkey');
              let newAlbum = $('#txt-'+viewkey).val();
  
              // Checks if album name is empty
              if (newAlbum === '') {
                  alert('Please enter an album name');
                  return false;
              } 
  
              $.ajax({
                  type: &quot;POST&quot;,
                  url: &quot;&lt;?= base_url(); ?&gt;/users/members/manage_uploads&quot;,
                  dataType: &quot;JSON&quot;,
                  data: {
                      [csrfName]: csrfHash,
                      &quot;album_name&quot;: newAlbum,
                      &quot;viewkey&quot;: viewkey,
                  },
                  headers: {
                      'X-Requested-With': 'XMLHttpRequest',
                  },
                  success: function(data) {
                      var res = data;
  
                      // Update CSRF hash
                      csrfName = res.csrfName;
                      csrfHash = res.csrfHash;
  
                      // Display new album name in table
                      $('#'+viewkey).html(newAlbum);
  
                      // Add new album name to all dropdown radio buttons
                      addNewRadioItem(viewkey, newAlbum);
  
                      alert(res.message);
                  }
              });
          });
      });
  
          function addNewRadioItem(viewkey, albumName) {
              var containers = document.querySelectorAll('.album-list')
  
              // Create new album radio in dropdown menu
              var label = document.createElement('label');
              var input = document.createElement('input');
              var span = document.createElement('span');
  
              label.setAttribute('class', 'album-select');
              label.innerHTML += albumName+' &lt;i class=&quot;fa-solid fa-xmark&quot; data-viewkey=&quot;'+viewkey+'&quot; data-albumName=&quot;'+albumName+'&quot;&gt;&lt;/i&gt;';
  
              input.setAttribute('type', 'radio');
              input.setAttribute('name', 'album_radio');
              input.setAttribute('class', 'album-radio');
              input.setAttribute('value', albumName);
              input.setAttribute('data-viewkey', viewkey);
              
              span.setAttribute('class', 'checkmark');
  
              label.appendChild(input);
              label.appendChild(span);
  
              //container.appendChild(label);
              $(containers).append(label);
  
              // Sorts radio options with added album
              sortNewRadio();
      }
  
      function sortNewRadio() {
          var divList = document.querySelectorAll('.album-list');
          var divArray = [...divList];
  
          for (const elem of divList){
              var listItems = $(elem).children('label').get();
  
              listItems.sort(function(a, b) {
                  var A = $(a).text().toUpperCase();
                  var B = $(b).text().toUpperCase();
  
                  return A.localeCompare(B);
              })
  
              $(elem).empty().append(listItems);    
          }
      }
  &lt;/script&gt;
  </code></pre>
  <p>And here is my html:</p>
  <pre class="lang-php prettyprint-override"><code>&lt;?php if (! empty($uploads)) {
              foreach ($uploads as $row) { ?&gt; 
          &lt;tr&gt;
              &lt;td class='upload-image'&gt;
                  &lt;img src= '&lt;?= base_url('/assets/img/uploads/' . $row-&gt;filename) ?&gt;', alt=' &lt;?= esc($row-&gt;title) ?&gt;' class='upload-thumbnail'&gt;
              &lt;/td&gt;
  
              &lt;td class='upload-album'&gt;
                  &lt;div class='album-dropdown'&gt;
                      &lt;span id='&lt;?= esc($row-&gt;viewkey); ?&gt;'&gt;
                          &lt;?= esc($row-&gt;album_name); ?&gt;
                      &lt;/span&gt;
                      &lt;div class='album-dropbtn' title='Move to Album'&gt;
                          &lt;i class=&quot;fa-solid fa-square-caret-down&quot; &gt;&lt;/i&gt;
                      &lt;/div&gt;
                  
                      &lt;div class='album-dropdown-content'&gt;
                          &lt;label class='album-select new-album-select'&gt;New Album
                              &lt;input type='radio' name='new_album_radio'  class='new-album-radio'/&gt;
  
                              &lt;span class='checkmark'&gt;&lt;/span&gt;
  
                              &lt;input type='text' name='new_album' class='new-album-text' id='txt-&lt;?= esc($row-&gt;viewkey); ?&gt;'/&gt;
  
                              &lt;button class='new-album-button' data-viewkey='&lt;?= $row-&gt;viewkey; ?&gt;'&gt;Create&lt;/button&gt;
                          &lt;/label&gt;
                      
                           &lt;!-- Javascript generates album radio dropdown list --&gt;
                           &lt;?php if (! empty($albums)) {
                                  foreach ($albums as $album) { ?&gt;
                                      
                                      &lt;label class='album-select'&gt;
                                          &lt;?= esc($album-&gt;album_name); ?&gt;
  
                                          &lt;i class=&quot;fa-solid fa-xmark&quot; data-viewkey='&lt;?= esc($row-&gt;viewkey); ?&gt;' data-album='&lt;?= esc($row-&gt;album_name); ?&gt;'&gt;&lt;/i&gt;
  
                                          &lt;input type='radio' name='album_radio' value='&lt;?= $album-&gt;album_name; ?&gt;' class='album-radio' data-viewkey='&lt;?= esc($row-&gt;viewkey); ?&gt;'/&gt;
                                          
                                          &lt;span class='checkmark'&gt;&lt;/span&gt;
                                      &lt;/label&gt;
                              &lt;?php }} ?&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/td&gt;
  </code></pre>