Retrieving javascript combobox value

0

I have the following situation:

I need to know a way to make the value of a combobox option the subject of an email that is sent from the site.

Ex: I have two combobox separated area and sector, when selecting these two options I need the subject of the email to be the option that was selected: área > setor

    
asked by anonymous 23.09.2015 / 14:59

1 answer

0

Using just JavaScript:

HTML

<select id="area" name="area">
    <option value="">Selecione</option>
    <option value="Informática">Informática</option>
    <option value="RH">RH</option>
</select>

<select id="setor" name="setor">
</select>

JavaScript (I used Jquery to facilitate):

$(function(){
    var setores = {
        "Informática": ["Sistemas", "Suporte", "Redes"],
        "RH": ["Folha de pagamento", "Benefícios", "Contratações"]
    };

    $("#area").on('change', function(){
        var options = $("#setor");
        options.find('option').remove();

        if($(this).val() == "") return;

        $.each(setores[$(this).val()], function() {
            options.append
                ($("<option />").val(this).text(this)
                );
        });
    });
}); 

Example on JSFiddle

In php just get the values of the two select and concatenate.

$_POST['area'].' > '.$_POST['setor']

The values of select can be done via ajax as well

    
23.09.2015 / 15:18