<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="./css/main.css">
<title>Document</title>
</head>
<body>
<div id="container">
<h1>회원가입</h1>
<form action="#" id="register">
<ul id="user-info">
<li>
<label for="user-id" class="field">아이디</label>
<input type="text" name="user-id" id="user-id" placeholder="4~15자리의 영문과 숫자로 입력" required>
</li>
<li>
<label for="email" class="field">이메일</label>
<input type="email" name="email" id="email" required>
</li>
<li>
<label for="user-pw1" class="field">비밀번호</label>
<input type="password" name="user-pw1" id="user-pw1" placeholder="8자리 이상" required>
</li>
<li>
<label for="user-pw2" class="field">비밀번호 확인</label>
<input type="password" name="user-pw2" id="user-pw2" required>
</li>
<li>
<label class="field">메일링 수신</label>
<label class="r"><input type="radio" value="yes" name="mailing">예</label>
<label class="r"><input type="radio" value="no" name="mailing">아니오</label>
</li>
</ul>
<ul id="buttons">
<li>
<input type="button" class="btn btnBlack" value="가입하기">
</li>
<li>
<input type="reset" class="btn btnGray" value="취소">
</li>
</ul>
</form>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
const frmRegister = document.getElementById('register');
const userId = document.getElementById('user-id');
const btnSubmit = document.querySelector('input[type=button]');
btnSubmit.addEventListener('click', function () {
console.log(userId.value.length);
if (userId.value.length < 4 || userId.value.length > 15) {
alert('4~15자리의 영문과 숫자를 사용하세요.');
userId.select();
}
frmRegister.submit();
});
const pw1 = document.querySelector('#user-pw1');
pw1.addEventListener('change', function() {
if(pw1.value.length < 8) {
alert('비밀번호는 8자리 이상이여야 합니다.');
pw1.value = '';
pw1.focus();
}
});
const pw2 = document.querySelector('#user-pw2');
pw2.addEventListener('change', function() {
if(pw1.value !== pw2.value) {
alert('암호가 다릅니다. 다시 입력하세요');
pw2.value = '';
pw2.focus();
pw1.setAttribute('type', 'text');
}
})
});
</script>
</body>
</html>