Javascript-форум (https://javascript.ru/forum/)
-   Events/DOM/Window (https://javascript.ru/forum/events/)
-   -   Проверка полей (https://javascript.ru/forum/events/70697-proverka-polejj.html)

Dilettante_Pro 27.09.2017 16:26

AndrewDanilin,
А зачем вам нужен такой телетайпный стиль? Если бы поля как-то зависели друг от друга - в зависимости от того, что введено в предыдущем, выбирается следующее поле - тогда это имело бы смысл. А при равноправных полях зачем? Все поля можно заполнять в любой последовательности, независимо друг от друга

AndrewDanilin 27.09.2017 16:38

сам скрипт уже написан постраничного перехода, вопрос в том, что к нему необходимы обязательный поля.. а допереть как их сделать, я не могу. нужен именно постраничный.

Dilettante_Pro 27.09.2017 17:01

Цитата:

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

Несколько раз перечитал и не понял

AndrewDanilin 27.09.2017 17:06

Буду краток тогда, нужен телетайпный стиль с обязательными полями на каждом тапе

Dilettante_Pro 27.09.2017 18:38

с некоторыми недоработками
<!DOCTYPE html>
<html >
<head>
</head>
<body>
	<div class="wrapper">
		<form action="#" method="post">
			<div class="step">
				<p class="step">Введите своё имя</p>
				<p><strong>Имя:</strong><input type="text" name="msg" id="msg" placeholder="Введите имя"></p>
			</div>
			<div class="step">
				<p class="step">Введите вашу фамилию</p>
				<p><strong>Фамилия:</strong><input type="text" name="surname" placeholder="Введите фамилию"></p>
			</div>
			<div class="step">
				<p class="step">Введите ваш email</p>
				<p><strong>Email:</strong><input type="text" name="email" placeholder="Введите ваш email"></p>
			</div>
			<p class="talign">
				<a href="#" class="back">Назад</a>
				<a href="#" class="next">Далее</a>
				<input type="submit" value="Завершить" onClick="Thanks();">
			</p>
		</form>
	</div>
	<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
	<script>
$(document).ready(function() {
	var steps = $("form").children(".step").hide();
        $('a.back').hide();
        $('a.next').hide();
        $('input[type=submit]').hide();

	var current_step = 0;
        $(steps[current_step]).show();

	$(steps).on('input', function() {
            if($(this).find('input').val().length > 2) {
                if(current_step < steps.length - 1) {
                     $('a.next').show();
                     $("form input[type=submit]").hide();
                }
                 else  {
                     $('a.next').hide();
                     $("form input[type=submit]").show();
                }
            }
            else { 
                $('a.next').hide(); 
                $("form input[type=submit]").hide(); 
            }
        });

	$("a.next").click(function(){
                  $(steps[current_step]).hide(); 
		  current_step++;
                  $(steps[current_step]).show();
                  $(this).hide();
                 current_step > 0 ? $('a.back').show() : $('a.back').hide();
	});
	
	$("a.back").click(function(){
		if (current_step == 1) { 
			$(this).hide();
		}
		$("form input[type=submit]").hide();
		$("a.next").show();
                $(steps[current_step]).hide();
		current_step--;
                $(steps[current_step]).show();
	});
	

	
});

function Thanks(){
jQuery("body").empty();	// очищаем тело документа
jQuery("body").append("<h2><center>Спасибо!</center></h2>");
}
	</script>
</body>
</html>

AndrewDanilin 27.09.2017 19:02

Спасибо большое, буду разбираться с js!


Часовой пояс GMT +3, время: 20:51.