Enter value in the input text closest to you

0

Good afternoon guys, I have a problem with my jquery is the following, I will have several forms in one page ... When typing in each "board" field my jquery inserts a value in the next field of the same form.

I tried to use the closest ("form"). find ("# concessionaire") but I did not succeed

Here is a link from jsfiddle trying to represent what I want to happen

link

    
asked by anonymous 21.08.2016 / 22:55

2 answers

0

I do not know if it's the best way, but it might solve your problem! link

<form>
        <label for="placa">Placa:</label>
        <input type="text" class="placa">

        <label for="concessionaria">Concessionaria:</label>
        <input type="text" name="concessionaria" id="concessionaria">
</form>
<form>
        <label for="placa">Placa:</label>
        <input type="text" class="placa">

        <label for="concessionaria">Concessionaria:</label>
        <input type="text" name="concessionaria" id="concessionaria">
</form>
<form>
        <label for="placa">Placa:</label>
        <input type="text" class="placa">

        <label for="concessionaria">Concessionaria:</label>
        <input type="text" name="concessionaria" id="concessionaria">
</form>

javascript:

$(".placa").on('input', function() {
    $(this).parent().find('#concessionaria').val($(this).val());
});
    
24.08.2016 / 14:14
0

Change the script to:

$(".placa").on('input', function () {
            $(this).parent().find("input[name$='concessionaria']").val($(this).val());
        });
    
04.05.2017 / 21:12