jQuery Form Handling
jQuery 폼검사 예 ( Form Handling )
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>jQuery Test</title>
<style type="text/css">
<script type="text/javascript" src="jquery-2.1.1.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#form1').submit(function(){
var id = $(this).find('input[name=id]').val();
var pwd= $(this).find('input[name=pwd]').val();
if(id=='' ||pwd=='') {
alert('아이디와 비밀번호를 입력해주세요');
window.event.preventDefault();
return;
}
if(confirm('입력된 내용을 서버로 전송하시겠어요?')) {
alert('폼을 전송합니다');
}else{
window.event.preventDefault();
}
}
});
</script>
</head>
<body>
<form id="form1" action="proc.jsp" method="post">
아이디 <input type="text" name="id"><br>
비밀번호<input type="password" name="pwd"><br>
<input type="submit" value="로그인"><br>
</form>
</body>
</html>