Вход

Просмотр полной версии : Вставить в Input данные из других input'ов


djonA
12.06.2015, 18:11
Помогите вставить данные из 3 input в 1 input главный.
Как такое реализовать через class'ы.

Сделал через onkeydown, работает, но вставляет только данные из текущего input, а мне надо что бы оно проходило по всем input и вставляло данные из них в главный input и разделяло их через +

Вот как сделал я :
<input type="text" value="" id="main">

<input type="text" value="" class="child" onkeyup="document.getElementById('main').value=this.value;">
<input type="text" value="" class="child" onkeyup="document.getElementById('main').value=this.value;">
<input type="text" value="" class="child" onkeyup="document.getElementById('main').value=this.value;">

caetus
12.06.2015, 19:28
<input type="text" value="" id="main">

<input type="text" value="" class="child" onkeyup="document.getElementById('main').value+= this.value;">
<input type="text" value="" class="child" onkeyup="document.getElementById('main').value+= this.value;">
<input type="text" value="" class="child" onkeyup="document.getElementById('main').value+= this.value;">

Endy
12.06.2015, 20:22
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="https://cdn.rawgit.com/finom/balalaika/master/balalaika.min.js"></script>
<script>
$(function() {
$.index=function(elem){var i=0;while(elem=elem.previousSibling){elem.nodeType ==1&&i++}return i}
var data = {},
output;
$('.child').on('keyup', function() {
data['input' + $.index(this)] = this.value;
output = Object.keys(data).map(function(e) {
return data[e];
});
main.value = output.join(' ');
});
});
</script>
</head>

<body>
<input type="text" value="" id="main" />
<input type="text" value="" class="child" />
<input type="text" value="" class="child" />
<input type="text" value="" class="child" />

</body>

</html>

вместо разделителя +, поставил пробел.