M
M
Maurice Mulyashov2017-05-12 00:17:26
JavaScript
Maurice Mulyashov, 2017-05-12 00:17:26

How to write selected values ​​from select to input if they (input and select) are dynamic?

Hello, clarification of the question: an unknown number of blocks are created in the loop (the number depends on the data in the database), each block has a select and an input, how to get this input in order to write the changing select values ​​\u200b\u200bto it, is it impossible to identify it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stalker_RED, 2017-05-12
@addonmis

Something like this, for example:

$('select').on('change', function(){ // при событии change
  var sel = $(this)
  sel.closest('.block') // ищется ближайший родитель .block (обертка, объединяющая select и input)
      .find('input') // в нем ищется инпут
      .val(sel.val()) // и записывается значение
})

If the markup is simple and select and input don't have any extra wrappers, then closest + find can be simplified to .siblings('input')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question