select does not work Ajax

0

Good morning, I did a search using Ajax using "input". Now I need to do the same form of search, but instead of being an "input", I have to use a "select". I already tested using input and it worked. But using "select" does not. What is wrong?

<div id="content">
        <div id="result">
            <TABLE>
                #TBODY#
            </TABLE>
        </div>
    </div>
        <div id="busca">
            <select id="option" name="option">
                                <option value="1">Janeiro</option>
                                <option value="2">Fevereiro</option>
                                <option value="3">Março</option>
                                <option value="4">Abril</option>
                                <option value="5">Maio</option>
                                <option value="6">Junho</option>
                                <option value="7">Julho</option>
                                <option value="8">Agosto</option>
                                <option value="9">Setembro</option>
                                <option value="10">Outubro</option>
                                <option value="11">Novembro</option>
                                <option value="12">Dezembro</option>
                            </select>

        </div>
<script type="text/javascript">
    $('#option').keyup(function () {
        var chars = (this.value);
        $.post(url + 'Ajax/showmes', {val: chars}, function (busca) {
            $('#result').html(busca);
        });
    });
</script>
    
asked by anonymous 15.02.2016 / 14:02

1 answer

5

I think the correct event would be change , in keyup it detects the key. The change is triggered when the element gets a different value, so when the user chooses another option it will be triggered.

keyup worked in the input case because it receives text input

<script type="text/javascript">
    $('#option').change(function () {
        var chars = (this.value);
        $.post(url + 'Ajax/showmes', {val: chars}, function (busca) {
            $('#result').html(busca);
        });
    });
</script>
    
15.02.2016 / 14:19