반응형

아이디 입력 창에서 입력 하지 않을 경우 경고 주는 방법.

사용 방법 주석 확인.


HTML Forms










1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<!DOCTYPE html>
<html>
<body>
 
<h2>HTML Forms</h2>
 
<form action="#이동할곳 URL#" name="login_form">
  <label for="fname">ID:</label><br>
  <input type="text" id="id_val" name="id_val" placeholder="아이디"><br>
  <!-- input 박스 안 글자 넣기 = placeholder -->
  <label for="lname">Password:</label><br>
  <input type="password" id="pw_val" name="pw_val" placeholder="비밀번호"><br><br>
  <input type="button" value="로그인" onclick="check_input()">
</form>
<script type="text/javascript">
function check_input() {
    if (!document.login_form.id_val.value)
    // login_form 이름을 가진 form 안의 id_val 의 value가 없으면
    {
        alert("아이디를 입력하세요!");
        document.login_form.id_val.focus();
        // 화면 커서 이동
        return;
    }
    if (!document.login_form.pw_val.value)
    {
        alert("비밀번호를 입력하세요!");
        // 화면 커서 이동
        return;
    }
    document.login_form.submit();
    // 모두 확인 후 submit()
 }
</script>
</body>
</html>
 
cs


반응형