회원가입
* {
margin: auto;
text-align: center;
}
#join {
border-collapse: collapse;
}
th,td {
border: 1px solid
}
<form action="#" method="post">
<table id=join>
<caption>회원가입 입력</caption>
<colgroup>
<col>
<col>
</colgroup>
<tbody>
<tr>
<th scope="row"><label for="id">아이디</label></th>
<th><input type="text" id="id" title="아이디 입력" placeholder="아이디를 입력하세요"></th>
</tr>
<tr>
<th scope="row"><label for="pw">비밀번호</label></th>
<th><input type="text" id="pw" title="비밀번호 입력" placeholder="비밀번호를 입력하세요"></th>
</tr>
<tr>
<th scope="row"><label for="r_pw">비밀번호 재입력</label></th>
<th><input type="text" id="r_pw" title="비밀번호 재입력"></th>
</tr>
<tr>
<th scope="row"><label for="email">이메일</label></th>
<th><input type="text" id="email" title="이메일아이디 입력">@<input type="text" title="이메일주소 입력"></th>
</tr>
<tr>
<th scope="row"><label for="hp">핸드폰 번호</label></th>
<td>
<select id="hp" title="휴대폰 앞자리 선택">
<option>선택</option>
<option>010</option>
<option>011</option>
</select> -
<input type="text" title="휴대폰 번호 중간 4자리 입력"> -
<input type="text" title="휴대폰 번호 끝 4자리 입력">
</td>
</tr>
<tr>
<td colspan="2">
<input type="submit" value="회원가입"><input type="reset" value="취소">
</td>
</tr>
</tbody>
</table>
</form>
로그인
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<title>폼</title>
</head>
<body>
<form id="form" action="#" method="post">
<fieldset>
<legend>로그인</legend>
<p>아이디 : <input type="text" name="id"></p>
<p>비밀번호 : <input type="password" name="pw"></p>
<p><input type="hidden" name="name"></p>
<input type="submit" value="로그인">
<br>
<span>입력한 아이디 : </span><span id="inputId"></span><br>
<span>입력한 비밀번호 : </span><span id="inputPw"></span>
</fieldset>
</form>
</body>
</html>
<script>
var userId = "fintech";
var userPw = "1234";
document.getElementsByTagName("form")[0].onsubmit = function() {
var inputId = this.id.value;
var inputPw = this.pw.value;
if(inputId == userId && inputPw == userPw){
alert("로그인 성공")
} else {
alert("아이디나 비밀번호 오류입니다!")
}
document.getElementById("inputId").textContent = inputId;
document.getElementById("inputPw").textContent = inputPw;
return false;
}
</script>
유효성 검사
* required / Javascript
* required="required" : HTML5부터 적용됨
* 입력 창에 입력하지 않고 확인을 창에 입력하라는 문구가 나타나는 기능
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<title>사용자 입력 속성</title>
<script>
function validate() {
var id = document.getElementById("id").value;
var pw = document.getElementById("pw").value;
if(!id){
alert("아이디 값을 입력하세요");
return false;
}
if(!pw){
alert("비밀번호 값을 입력하세요");
return false;
}
}
</script>
</head>
<body>
<form onsubmit="return validate();" action="#" method="post">
<fieldset>
<legend>필수입력 유효성 검사</legend>
<p>
<label for="id">* 아이디</label>
<input type="text" id="id" autocomplete="on" title="아이디 입력">
</p>
<p>
<label for="pw">* 비밀번호</label>
<input type="password" id="pw" title="비밀번호 입력">
</p>
<p>
<input type="submit" value="확인">
</p>
</fieldset>
</form>
</body>
</html>