Add values in select with javascript

0

Dear, I'm trying to add value in a select with javascript.

I have 2 select's, 1 - Company and 2 - Branch. I will enter different values depending on the value chosen in the 1 - Company.

I looked in some places but not found a solution to the problem. I have the following code.

<script type="text/javascript">
    document.getElementById("teste").onClick = function() {
        alert("239309");
        if(document.getElementById("selectEmpresa").value() == "Escolha uma opção"){
            var comboRamo = document.getElementById("selectRamo");

            var opt0 = document.createElement('option');
            opt0.value = "0";
            opt0.text = "Selecione uma empresa";
            comboRamo.add(opt0, comboRamo.options[0]);

        }
    }

</script>

This "test" is a button I'm using to test. But I want to put for any action performed on select 1 - Company.

    
asked by anonymous 10.02.2018 / 17:40

1 answer

0

I got syntax error.

<script type="text/javascript">
    $(".selectEmpresa").each(function() {
        if($(this).val() == "Escolha uma opção"){
            var comboRamo = document.getElementById("selectRamo");
            var opt0 = document.createElement('option');
            opt0.value = "0";
            opt0.text = "Selecione uma empresa";
            comboRamo.add(opt0, comboRamo.options[0]);
        }
    });

</script>

I was without the parentheses and semicolon in the end.

    
10.02.2018 / 17:49