3
I need to order a select alphabetically.
I tried to use this function I found on the internet
function ordenarSelect(){
f$(".slc_Reuniao").html($("option", $(".slc_Reuniao")).sort(function(a,b){
return a.text == b.text ? 0 : a.text < b.text ? -1 : 1;
}));
};
My initial select is:
<select class="slc_Reuniao">
<option value="SO" selected>--</option>
</select>
I run a function that adds dynamically with append the names that came back from query. I must order them.
However it is not working, on the contrary it is generating new options, am using IndexedDB as database it is also based on javascript, I tried to search for something that at the moment I am searching the data in the database I sort itself as in the sql but I couldn’t find anything about it.
How should I do this ?
On the same page I have 3 select whose content is equal.
The implementation way is when I click on a menu located in a sidemenu, triggers an event that I describe below.
$(document).on("click", "#cadReu", function(evt)
{
var w_codigo_turma = sessionStorage.getItem('codigo');
carregaSelectAluno(w_codigo_turma);
ordenarSelect();
activate_page("#cadastro_REUNIAO");
});
After it calls the function carregarSelectAluno(), I won’t add by size but its function is just to create the <option value""></option> and add in the field where caught by the command $wrapper = document.querySelector('.slc_Reuniao'); and put in select this way
$( ".slc_Reuniao" ).each(function() {
$(this).append(HTMLNovo);
});
After this I call the function ordenarSelect() which is where I am placing the functions indicated by the answers to my question. Both tips are giving same problem. It is not organizing and it is conducting. A problem I identified that is when I return it adds the names again.

I wanted something dynamic that didn’t need to add events to clicks,
– Renan Rodrigues
I edited the answer, see if it helps you
– Randrade
My friend, the method indicated for you is giving something interesting, when I go on the page it performs only 4 changes, if I go out and enter the page it does with all the options of select but it blocks 3 previous select and the last only that is working. in the log gave the following result.
Montagem dos selects concluido com sucesso. main.js:29
0 
1 
2 
3 
Montagem dos selects concluido com sucesso. main.js:29
0 
1 
2 
3 
4 
5 
6 
7 
8 
9 
10
11
12
13
14
15– Renan Rodrigues
I didn’t understand the editions of your question. You own several
select'sand want to sort everyone when accessing the page, or want to sort after some interaction, or both options?– Randrade
No, I need to order all select when accessing the page, in fact I ride it disorderly and I want to order and send to page.
– Renan Rodrigues
You can change your answer to suit ?
– Renan Rodrigues
@Renanrodrigues I edited the answer again. Check if this is what you want.
– Randrade
Something crazy is happening, it just takes the first field of select and how it is
outroit does not organize. I am calling the function as soon as I have just put everything in select. What may be happening ? What is my mistake ?– Renan Rodrigues