Lỗi Form-Login ko thể chạy được JavaScript

Các bác giúp em cs ạ . Em mới học HTML,CSS, JS em xem bài hướng dẫn trên YOUTUBE và làm theo họ nhưng sao file JS của em ko thể chạy được trong khi code em giống code đó ạ :frowning:
em để 3 file index.html,index.css,index.js ạ.

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Login</title>
	<!-- Latest compiled and minified CSS & JS -->
	<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
	<script src="//code.jquery.com/jquery.js"></script>
	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
	<link rel="stylesheet" href="index.css">
</head>
<body>	
	<section id="main">
		<div class="container">
			<div class="row">
				<div class="col-md-6 col-md-offset-3">
					<div class="panel panel-login">
						<div class="panel-heading">
							<h4>LOGIN !</h4>
						</div>
						<div class="panel-body">
							<form id="form-login" action="" method="POST" role="form" >
								<div class="form-group">
									<label for="username">Username</label>
									<input type="text" class="form-control" id="username" placeholder="username">
								</div>
								<div class="form-group">
									<label for="password">Password	</label>
									<input type="password" class="form-control" id="password" placeholder="password">
								</div>
								<div class="row">
									<div class="col-md-6">
										<button type="submit" class="btn btn-primary btn-block" >Submit</button>
									</div>	
									<div class="col-md-6">
										<a href="" class="btn btn-link"><p><b>Forgot your password</b></p></a>
									</div>						
								</div>
							</form>
						</div>
					</div>
				</div>
			</div>
		</div>
	</section>
	<script src="index.js"></script>
</body>
</html>`

ĐÂY LÀ FILE INDEX.JS

var CORRECT_USER = 'laptrinh.io';
var CORRECT_PASS = 'ozawa';
var inputUsername =document.getElementByid('username');
var inputPassword =document.getElementByid('password');

var formLogin = document.getElementByid('form-login');
if (formLogin.attachEvent) {
	formLogin.attachEvent('submit',onFormSubmit);
} else {
	formLogin.addEventListener('submit',onFormSubmit);
}


function onFormSubmit(e){
		var username = inputUsername.value;
		var password = inputPassword.value;
		if(username == CORRECT_USER && password == CORRECT_PASS){
				alert('Đăng nhập thành công');
		}
		else
			{alert('Đăng nhập thất bại ');}
}

Có thể lỗi ở getElementById thay cho getElementByid, value là thuộc tính, không phải phương thức

1 Like

uhm tks banj dde mình thử lại xem mình mới học nên ko biết bạn à :slight_smile:

được rồi bạn à tks bạn nhiều nha :wink: mình xin xóa topic

83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?