1. Input Values

2. form submit의 유효성 체크

3. event part-1(preventDefault function)

4. event part-2(link의 기본 동작)

1. Input Values

1-1) Javascript

const loginFrom = document.getElementById("login-form");
const loginInput = document.querySelector("input");
const loginButton = document.querySelector("button");

const loginInput = document.querySelector("#login-form input");
cosnt loginButton = document.querySelector("#login-form button");

function onLoginBtnClick() {
	console.log("click!!!!!");
}

loginButton.addEventListener("click", onLoginBtnClick);

1-2) HTML

<div id="login-form" >
	<input type="text" placeholder="What is your name?" />
	<button>Login</button>
</div>

2. form submit의 유효성 체크

2-1) required

<body>
<form id="loing-form">
	<input required maxlength="15" type="text" placeholder"What is your name?"/>
	<button>Login</button>
	<input type="submit" value="Login" />
</form>
<script src=app.js"></script>
</body>

3. event part-1(preventDefault function)

const loginForm = document.querySelector("#login-form");
const loginInput = document.querySelector("#login-form input");

function onLoginSubmit(event) {
	event.preventDefault();        // 새로고침 멈추기
	console.log(event);            // app.js:7
	console.log(loginInput.value); // app.js:8
}

loginForm.addEventListener("submit", onLoginSubmit);

4. event part-2(link의 기본 동작)

4-1) HTML

<body>
	<form id="login-form">
		<input required maxlength="15" type"text" placeholder="What is your name?" />
		<input type="submit" value="Login" />
		<a href="<https://nomadcoders.co>">Go to courses</a>
	</form>
</body>

4-2) Javascript

const loginForm = document.querySelector(#login-form);
const loginInput = document.querySelector(#login-form input);
const link = document.querySelector("a");

function onLoginSubmit(event) {
	event.preventDefault();
	console.log(loginInput.value);
}

function handleLinkClick(event) {
	event.preventDefault();
	console.log(event);
	// dir() 세부사항을 볼 수 있음.
	console.dir(event);
}

loginForm.addEventListener("submit", onLoginSubmit);
/* link.addEventListener("click", handleLinkClick());
	 ()를 추가하면 한 번만 실행되고 그걸로 끝임.
	 *** 절대 넣지 말기!!! ***	
*/
link.addEventListener("click", handlerLinkClick);

4-2)-1. Console

Untitled

4-2)-2. console.dir()

Untitled