Копирование с input в input
Добрый день! Незнаю как реализовать следующую задачу. Есть 4 поля. Первое поле где полностью пишится Фамилия Имя Отчество, есть второе поле где пишится просто фамилия, третье под имя и четвертое поле под отчество. Как сделать так чтоб при написании первого поля чтоб автоматически заполнялись поля 2,3,4 своим значениями.
|
Murk,
а как определить окончание записи в первое поле? |
Цитата:
|
Murk,
oninput split |
Цитата:
|
Murk,
рисуйте html Пожалуйста, отформатируйте свой код! Для этого его можно заключить в специальные теги: js/css/html и т.п., например: [js] ... ваш код... [/js] О том, как вставить в сообщение исполняемый javascript и html-код, а также о дополнительных возможностях форматирования - читайте http://javascript.ru/formatting. |
Murk,
<!DOCTYPE html>
<html>
<head>
<title>Untitled</title>
<meta charset="utf-8">
<style type="text/css">
</style>
<script>
window.addEventListener("DOMContentLoaded", function() {
var inp = document.querySelector(".in"),
out = document.querySelectorAll(".out");
inp.addEventListener("input", function(event) {
inp.value.split(/\s+/).forEach(function(text,i) {
out[i] && (out[i].value = text)
});
})
});
</script>
</head>
<body>
<input type="text" class="in">
<input type="text" class="out">
<input type="text" class="out">
<input type="text" class="out">
</body>
</html>
|
Цитата:
|
Murk,
от вас требовалось написать строки 25-28 хотя бы ... :( |
Цитата:
|
Цитата:
|
Murk,
так укажите ваши id в строках 12, 13 "#id" и "#id,#id,#id" вместо классов |
Цитата:
<!DOCTYPE html>
<html>
<head>
<title>Untitled</title>
<meta charset="utf-8">
<style type="text/css">
</style>
<script>
window.addEventListener("DOMContentLoaded", function() {
var inp = document.querySelector("#idname"),
out = document.querySelectorAll("#idname_cf2275ee56","#idname_c1fcb405d4","#idname_a49c87b871");
inp.addEventListener("input", function(event) {
inp.value.split(/\s+/).forEach(function(text,i) {
out[i] && (out[i].value = text)
});
})
});
</script>
</head>
<body>
<input type="text" id="idname">
<input type="text" id="idname_cf2275ee56">
<input type="text" id="idname_c1fcb405d4">
<input type="text" id="idname_a49c87b871">
</body>
</html>
|
Цитата:
Цитата:
|
Murk,
Знаете ли вы селекторы?
<!DOCTYPE html>
<html>
<head>
<title>Untitled</title>
<meta charset="utf-8">
<style type="text/css">
</style>
<script>
window.addEventListener("DOMContentLoaded", function() {
var inp = document.querySelector("#idname"),
out = document.querySelectorAll("[id^='idname_']");
inp.addEventListener("input", function(event) {
inp.value.split(/\s+/).forEach(function(text,i) {
out[i] && (out[i].value = text)
});
})
});
</script>
</head>
<body>
<input type="text" id="idname">
<input type="text" id="idname_cf2275ee56">
<input type="text" id="idname_c1fcb405d4">
<input type="text" id="idname_a49c87b871">
</body>
</html>
|
| Часовой пояс GMT +3, время: 22:01. |