🌈JAVAScript

[JAVAScript]id, value, focus

김말자 2023. 2. 9. 16:52
728x90
728x90
BIG

https://hyejin283.tistory.com/285

 

[JSP] JSP안에 있는 내장 객체(request)

테이블 생성 create table member( id varchar2(20) primary key, pwd varchar2(20) not null, name nvarchar2(10) not null, mobile varchar2(20), regDate date default sysdate ); insert into member values('sugyungeeJJang','1234','홍길동',null,sysdate); ins

hyejin283.tistory.com

여기있는 폼을 이용해서 만들어보겠다.

<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>로그인 폼</title>
</head>
<body>
	<form method="post" action="dbLogin.jsp" onsubmit="return loginCheck()">
		<table>
			<tr>
				<td>아이디 :</td>
				<td><input type="text" name="id" id="id"></td>
			</tr>
			<tr>
				<td>암 &nbsp; 호 :</td>
				<td><input type="password" name="pwd" id="pwd"></td>
			</tr>
			<tr>
				<td colspan='2' align="center"><input type="submit" value="로그인"></td>
			</tr>
		</table>
	</form>
</body>
<script type="text/javascript">
	function loginCheck() {
		const id = document.getElementById("id");
		if(id.value.trim().length==0){
			alert("아이디를 입력하세요");
			id.value="";
			id.focus();
			return false;
		}
		const pwd = document.getElementById("pwd");
		if(pwd.value.trim().length==0){
			alert("비밀번호를 입력하세요");
			id.value="";
			id.focus();
			return false;
		}
		return true;
	}
</script>
</html>

const 안에  엘리먼트를 담고 그 벨류값이 비었으면 입력해주라고 쓰고, 벨류를 초기화해준 후 포커스를 맞춰준다.

 

728x90
반응형
BIG