Recovering value combobox javascript

Asked

Viewed 59 times

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 separate combobox area and sector, when selecting these two options precise that the subject of the email is the option that was selected: área > setor

  • you already have something code done ? if you have pole

  • You don’t need Javascript for this. Pure HTML and PHP can handle it.

  • Thiago, edit your question and put what you have already done.

1 answer

0

Using Javascript only:

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 make it easy):

$(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 in Jsfiddle

In php just take the values of the two select and concatene.

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

The values of select can be done via ajax too

Browser other questions tagged

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