How popular a runtime combobox

Asked

Viewed 45 times

1

As popular a combobox (Select) when clicking on another combobox, for example I have a combobox with 3 options when selecting an option it recharges the other with the options referring to the selected one, someone would know how to do it using javascript?

I found several examples before publishing the question but none me Atendei, so what I would like to do is identify the code below the problem is that when I initialize the page it displays 3 options of cities, in the case Macae appears twice until the user selects an option, and when I send the data and how the example works with filtering through Value it does not send the information I would like to send that would be important content for the user, follows the code below.

   <script type='text/javascript'>//<![CDATA[
        $(window).load(function(){
        var concelhos = $('select[name="cmbcidade"] option');
        $('select[name="cmbopcao"]').on('change', function () {
            var Cmbopcao = this.value;
            var novoSelect = concelhos.filter(function () {
                return $(this).data('distrito') == Cmbopcao;
            });
            $('select[name="cmbcidade"]').html(novoSelect);
        });
        });//]]> 
    </script>

</head>
<body>
<p>Selecione a seguinte opção: 
<select name="cmbopcao" size="1" width="180" class="COMBODISTCSS" id="COMBOFAB" tabindex="1">
    <option value="dois">Escritório Mobiliado</option>
    <option value="dois">Escritório Virtual</option>
    <option value="dois">Escritório Eventual</option>
    <option value="um">Escritório de Treinamento</option>
    <option value="dois">Escritório de Reunião</option>
    <option value="dois">Video Conferencia</option>
</select></p>

<p>Selecione a cidade:
<select name="cmbcidade" size="1" width="195" class="COMBOCONCCSS" id="COMBOCID" tabindex="1">
    <option data-distrito="dois" value="Macae">Macae</option>
    <option data-distrito="dois" value="Rio de Janeiro">Rio de Janeiro</option>
    <option data-distrito="um" value="Macae">Macae</option>
</select></p>

</body>
</html>
  • Could you please put the code you’ve made so far?

  • You can do it with ajax.

  • 1

    Look at that question, possible duplicate.

  • Bruno, give more details about your problem. Where does the first select data come from? how is your code?

  • Bruno, I believe that your problem has a solution in the answer in the duplicate link. If you don’t tell me here that I reopen and we give more clarification.

  • I published the code

Show 1 more comment
No answers

Browser other questions tagged

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