$(document).on("click", "#download_releases", function(event) { event.preventDefault(); const releasable_ids = JSON.parse($("#selected_releases_form").attr('data-releasable-ids')); const total_entries = $('#total_entries').val(); const input_ids = $('').attr({ type: 'hidden', name: 'release_ids', value: JSON.stringify(releasable_ids) }); const search_query = $('').attr({ type: 'hidden', name: 'search_query', value: $("form input[type='search']").val() }); const type_filter = $('').attr({ type: 'hidden', name: 'type_filter', value: $('#type_filter_value').val() }); const download_count = releasable_ids.length > 0 ? releasable_ids.length : total_entries; $(this).parent().append(input_ids); $(this).parent().append(search_query); $(this).parent().append(type_filter); if (confirm(`${download_count} release(s) will be downloaded. Is this correct?`)){ Rails.fire($(this).parent()[0], 'submit'); } });