Javascript input select option with data-select

Asked

Viewed 446 times

1

I have the following javascript code and creates add the data-select attribute

Something like this but create select in javascript http://jsfiddle.net/dbg0a4zy/

As in this option in php but in javascript

 echo'<option data-select="'.$distrito.'" value= "'.$registoq['id_escalao'].'">'.$registoq['id_escalao'].' </option>';  

 // Celula 2 -Escalão
    // Cria um <td>
    var diasem = row.insertCell(2);
     // Cria o select
    var esc = document.createElement('select');
    // Da o nome ao select
    esc.name = 'escalao[]';
    esc.className = "form-control";
    esc.options[0] = new Option("iniciados", "1");
         esc.options[1] = new Option("juniores", "2");
 esc.options[2] = new Option("seniores", "3);
    diasem.appendChild(esc);

This is the code that I use to only show the classes associated with that mode, do I need data-select or is there another way ? is that I cannot create the data-select attribute in javascript

var selects = $('select[name="escalao[]"] option');
$('select[name="modalidade[]"]').on('change', function () {
var select = this.value;
var novoSelect = selects.filter(function () {
    return $(this).data('select') == select;
});
$('select[name="escalao[]"]').html(novoSelect);
});
  • There are many problems in this code... the code is like this in a file or joined PHP and Javascript only here in the question?

  • This all together and works after all, only I have a select with the modalities and this select presents all the levels, I want to put data-target to be able to filter

  • It seems to me that what you did to filter by Council is correct, is having some problem?

  • The problem is to create the data-select= in the input option created in javascript, with you in php but javascript is already another story the problem is even in creating this attribute in javascript

  • what version of jquery? tries with attr.. $(this). attr('data-select', 'test')

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.