PhoeniX5's avatar

Laravel Keyup function not working

I need to get some values from the database after entering a value in a text field, but nothing happens. Here is my code:

<div class="form-group">
    <label>Entrez le numéro de série</label>
    <input type="text" name="n_serie" required="required" class="form-control" />
</div>
<div class="form-group">
    <label>Panne signalée</label>
    <span id="panne"></span>
</div>

$('#n_serie').keyup(function(){
            event.preventDefault();
            var form_data = $(this).serialize();
            $.ajax({
                url:"{{ route('Reparation.getPanne') }}",
                method:"GET",
                data:form_data,
                dataType:"json",
                success:function(data)
                {
                    $('#panne').html(data.success);
                }
            });
        });
0 likes
4 replies
mironmg's avatar

we need the html as well. What kind of element is #n_serie ?

realrandyallen's avatar
Level 44

$('#n_serie') is targeting an element with an id of n_serie, your input doesn't have an id, the name attribute is n_serie

// give the input an id attribute...
<input type="text" id="n_serie" name="n_serie" required="required" class="form-control" />

// ...or find the input by name instead
$("input[name='n_serie']").keyup(...)
PhoeniX5's avatar

Really sorry I missed the id, I added attribute id to the text field.

1 like

Please or to participate in this conversation.