3

I need to synchronize all inputs with same name. I don't know inputs names.

Example:

<input type="text" placeholder="number" name="fields[340]" required="" value="">
<input type="text" placeholder="number" name="fields[340]" required="" value="">

So now I need to synchronize inputs values.

Problem is that I don't know input names. This is what I have so far.

var $inputs = $(":input");
$inputs.keyup(function() {
     $inputs.val($(this).val());
});

1 Answer 1

6

Use 'input[name="' + this.name + '"]' selector to get the inputs with same name.

var $inputs = $(":input");
$inputs.on('input',function() {
  $('input[name="' + this.name + '"]').val($(this).val());
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<input type="text" placeholder="number" name="fields[340]" required="" value="">
<input type="text" placeholder="number" name="fields[340]" required="" value="">
<br/>
<input type="text" placeholder="number" name="fields[341]" required="" value="">
<input type="text" placeholder="number" name="fields[341]" required="" value="">

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.