<select> does not work Ajax

Asked

Viewed 77 times

0

Good morning Guys, I did a search with Ajax using "input". Now I need to do the same way of searching, but instead of being an "input", I have to use a "select". I have 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>

1 answer

5


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

The keyup worked in the case of input 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>
  • 1

    That’s right, buddy. Thank you very much.

Browser other questions tagged

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