Script to play songs in sequential order

In my HTML I have a set of checkboxes where I choose two or more choices at the same time.
I have the following script done but the mp3s play my choices simultaneously. I needed help because I wanted them to play one after the other.

In my HTML I have a set of checkboxes where I choose two or more choices at the same time.
I have the following script done but the mp3s play my choices simultaneously. I needed help because I wanted them to play one after the other.

We would have to supply us the code to get a better look. Do you have a repo? Or is this in an online IDE?


<script type="text/javascript">
$(window).load(function() {

  $("#play_button").click(function() {
    var selected_items = $("#playlist td input:checked");

    if (selected_items.length == 0) {
      alert("Não foi seleccionada nada.");
    } else {

      var song = [];
     
      selected_items.each(function() {
        song.push($(this).data("song"));
       


      })
          song.forEach(e => new Audio(e).play());


    }
  });



  $("#selectall").click(function() {
    var c = this.checked;
    $("#playlist :checkbox").prop("checked", c);
  });
  $("#selectall_button").click(function() {
    var c;
    if ($(this).val() == "Select All") {
      c = true;
      $(this).val("Deselct All");
    } else {
      c = false;
      $(this).val("Select All");
    }

    $("#playlist :checkbox").prop("checked", c);
  });

});


</script>

<div class="mestre"><button class="bt bt-vd" style="margin-left:80px;" onclick="setColor(event)";>CHEFE DE SERVIÇO <br><label class="chk"><input name="check[]"   type="checkbox" data-song="chefe.mpeg"/><span></span></label></button></div>
<div class="mestre"><button class="bt bt-vd" onclick="setColor(event)";>EMERGÊNCIA MÉDICA<label class="chk"><input name="check[]"   type="checkbox" data-song="emedica.mpeg"/><span></span></label></button></div>

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

Thanks. Thank you very much. I hadn’t noticed how bad it was. Thank you for your help

So, yeah, you are just firing those off all at once. You need to find a way to queue them up and trigger the next when the previous ends. I think this SO post might have the right idea:

Thanks. I really appreciate your way of first forcing people to think and only then giving the answer. I tried. I’ve tried it in several ways but I can’t figure out how to get the click sequence or the choices. I appreciate your help. And the promise remains that I will apply myself more in the coming times to deepen my knowledge, which is still very little. Thanks.

OK, if you can put this in a repo, I or someone else might be able to take a deeper look.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.