4
In a form there are N occurrences of values for the same product, to facilitate I want to apply the same value to the subsequent inputs.
For example, using the structure below:
<input class="valor partida" type="text" name="novo_valor_partida-1" value="11,11" data-produto="0101000" data-id="1">
<input class="valor partida" type="text" name="novo_valor_partida-2" value="11,11" data-produto="0101000" data-id="2">
<input class="valor partida" type="text" name="novo_valor_partida-3" value="11,11" data-produto="0101000" data-id="3">
When you modify the value in input 1, 2 and 3 will also receive the value. If input 2 is changed, only input 3 receives the value and so on.
Since there are N fields, I will use the attribute data-produto
to select the inputs.
Does this guarantee that inputs will be analyzed in the same order as in html? Just curious.
– Oralista de Sistemas
@Renan not sure of the order, but the Docs say "Get all following siblings", therefore previous siblings will not be included.
– Sergio
Sergio, using Blur and an older version do not get the same result. I am using, unfortunately, version 1.4.4 and Blur event due to some checks I will do in input.
– Marcelo de Andrade
@Marcelodeandrade you mean you need to use the event
.blur()
? or you can use both?$('input').on('change blur', function() {
– Sergio
I can use both, but I believe that the version I am using will not help because error occurs
Uncaught TypeError: $(...).on is not a function
in the method other than not applying thenextAll
– Marcelo de Andrade
@Marcelodeandrade ah, because the
.on(
came later :) changes to.bind(
– Sergio
@Sergio one thing I noticed is that it "hangs" depending on the level of the element. For example: If the element is in a
TR
does not work. Example of the HTML I am using: jsfiddle– Marcelo de Andrade
@Marcelodeandrade in your example in the question the inputs are siblings hence the solution I indicated in the reply. If they are not, and you want to give the same value, you have to do it differently, for example: https://jsfiddle.net/4k3x49sL/1/ That’s why it’s important to have as much detail as possible for the answer to be accurate and to help.
– Sergio
I got it, @Sergio.
– Marcelo de Andrade