Скопировать содержимое textarea в другую textarea
Добрый день, в js вообще ничего не понимаю, методом тыка пытаюсь сделать копирование содержимого скопировать содержимое трех textarea, не зная их ID, <textarea name="product_attribute[0][product_attribute_description][1][text]" cols="40" rows="5"></textarea> <textarea name="product_attribute[1][product_attribute_description][1][text]" cols="40" rows="5"></textarea> <textarea name="product_attribute[2][product_attribute_description][1][text]" cols="40" rows="5"></textarea> в <textarea name="model" id="model" cols="50" rows="5">"Свой текст" (сюда значение первой textarea) <br> Свой текст (сюда значение второй textarea)<br> Свой текст (сюда значение третьей textarea)</textarea> что б вышло например Свой текст 11 Свой текст 22 Свой текст 33 все это дело в браузере, просто не хочется каждый раз вставлять в ручную текст, делаю кнопку которая скопирует и перенес дубль в другое место, то есть лишние действия убираю. Может подскажут.. )) |
<textarea name="product_attribute[0][product_attribute_description][1][text]" cols="40" rows="5">231213</textarea>
<textarea name="product_attribute[1][product_attribute_description][1][text]" cols="40" rows="5">123213213</textarea>
<textarea name="product_attribute[2][product_attribute_description][1][text]" cols="40" rows="5">213213123</textarea>
<textarea name="model" id="model" cols="50" rows="5"></textarea>
<button id="btn">скопировать</button>
<script>
document.querySelector('#btn').onclick = e => {
document.querySelector('#model').innerHTML = [].map.call(document.querySelectorAll('[name^="product_attribute"]'), el=>el.innerHTML).join('\n');
};
</script>
|
igorfelix89,
<!DOCTYPE html>
<html>
<head>
<title>Untitled</title>
<meta charset="utf-8">
<style type="text/css">
</style>
<script>
document.addEventListener("DOMContentLoaded", function() {
var a = document.querySelectorAll('[name*="product"]'),
d = document.querySelector('[name="model"]'),
b = [];
[].forEach.call(a, function(c, a) {
b.push(c.value);
c.addEventListener("input", function() {
b[a] = c.value;
d.value = b.join("\n")
})
})
});
</script>
</head>
<body>
<textarea name="product_attribute[0][product_attribute_description][1][text]" cols="40" rows="5"></textarea><br>
<textarea name="product_attribute[1][product_attribute_description][1][text]" cols="40" rows="5"></textarea><br>
<textarea name="product_attribute[2][product_attribute_description][1][text]" cols="40" rows="5"></textarea><br>
<textarea name="model" id="model" cols="50" rows="5"></textarea>
</body>
</html>
|
| Часовой пояс GMT +3, время: 07:19. |