묻고답하기
page_full_width" class="col-xs-12" |cond="$__Context->page_full_width">
질문 드립니다~! 폼을 자바스크립트로 공백체크 하는데 안돼네요...ㅜ.ㅜ
2003.06.01 18:49
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=euc-kr">
<script>
function check(f){
if (f.order.value == 0){
window.alert (" 회차를 입력하세요");
f.order.focus();
}
else if (f.num1.value == 0){
window.alert ("번호를 입력하세요");
f.num1.focus();
}
else if (f.num2.value == 0){
window.alert ("번호를 입력하세요");
f.num2.focus();
}
else if (f.num3.value == 0){
window.alert ("번호를 입력하세요");
f.num3.focus();
}
else if (f.num4.value == 0){
window.alert ("번호를 입력하세요");
f.num4.focus();
}
else if (f.num5.value == 0){
window.alert ("번호를 입력하세요");
f.num5.focus();
}
else if (f.num6.value == 0){
window.alert ("번호를 입력하세요");
f.num6.focus();
}
else{
f.submit();
}
}
</script>
</head>
<body>
<form name="lotto" method="post" action="lotto_input_save.php">
<table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#000000">
<tr align="center" bgcolor="#FFFFFF">
<td height="20" colspan="2">로또번호 입력폼</td>
</tr>
<tr align="center" bgcolor="#FFFFFF">
<td width="111" height="20">회차</td>
<td width="286"><input name="order " type="text" id="order " size="4" maxlength="4"></td>
</tr>
<tr align="center" bgcolor="#FFFFFF">
<td height="20">번호1</td>
<td><input name="num1" type="text" id="num1" size="2" maxlength="2"></td>
</tr>
<tr align="center" bgcolor="#FFFFFF">
<td height="20">번호2</td>
<td><input name="num2" type="text" id="num2" size="2" maxlength="2"></td>
</tr>
<tr align="center" bgcolor="#FFFFFF">
<td height="22">번호3</td>
<td><input name="num3" type="text" id="num3" size="2" maxlength="2"></td>
</tr>
<tr align="center" bgcolor="#FFFFFF">
<td height="20">번호4</td>
<td><input name="num4" type="text" id="num4" size="2" maxlength="2"></td>
</tr>
<tr align="center" bgcolor="#FFFFFF">
<td height="20">번호5</td>
<td><input name="num5" type="text" id="num5" size="2" maxlength="2"></td>
</tr>
<tr align="center" bgcolor="#FFFFFF">
<td height="20">번호6</td>
<td><input name="num6" type="text" id="num6" size="2" maxlength="2"></td>
</tr>
<tr align="center" bgcolor="#FFFFFF">
<td height="20" colspan="2"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr align="center">
<td width="34%"><input type="submit" name="Submit" value="연속입력"></td>
<td width="13%"><input name="button" type="button" onClick="javascript:check(this.form);" value="클릭"></td>
<td width="25%"><input type="reset" name="Submit3" value="취소"></td>
<td width="28%"><input type="button" name="Submit4" value="닫기"></td>
</tr>
</table></td>
</tr>
</table>
</form>
</body>
</html>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=euc-kr">
<script>
function check(f){
if (f.order.value == 0){
window.alert (" 회차를 입력하세요");
f.order.focus();
}
else if (f.num1.value == 0){
window.alert ("번호를 입력하세요");
f.num1.focus();
}
else if (f.num2.value == 0){
window.alert ("번호를 입력하세요");
f.num2.focus();
}
else if (f.num3.value == 0){
window.alert ("번호를 입력하세요");
f.num3.focus();
}
else if (f.num4.value == 0){
window.alert ("번호를 입력하세요");
f.num4.focus();
}
else if (f.num5.value == 0){
window.alert ("번호를 입력하세요");
f.num5.focus();
}
else if (f.num6.value == 0){
window.alert ("번호를 입력하세요");
f.num6.focus();
}
else{
f.submit();
}
}
</script>
</head>
<body>
<form name="lotto" method="post" action="lotto_input_save.php">
<table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#000000">
<tr align="center" bgcolor="#FFFFFF">
<td height="20" colspan="2">로또번호 입력폼</td>
</tr>
<tr align="center" bgcolor="#FFFFFF">
<td width="111" height="20">회차</td>
<td width="286"><input name="order " type="text" id="order " size="4" maxlength="4"></td>
</tr>
<tr align="center" bgcolor="#FFFFFF">
<td height="20">번호1</td>
<td><input name="num1" type="text" id="num1" size="2" maxlength="2"></td>
</tr>
<tr align="center" bgcolor="#FFFFFF">
<td height="20">번호2</td>
<td><input name="num2" type="text" id="num2" size="2" maxlength="2"></td>
</tr>
<tr align="center" bgcolor="#FFFFFF">
<td height="22">번호3</td>
<td><input name="num3" type="text" id="num3" size="2" maxlength="2"></td>
</tr>
<tr align="center" bgcolor="#FFFFFF">
<td height="20">번호4</td>
<td><input name="num4" type="text" id="num4" size="2" maxlength="2"></td>
</tr>
<tr align="center" bgcolor="#FFFFFF">
<td height="20">번호5</td>
<td><input name="num5" type="text" id="num5" size="2" maxlength="2"></td>
</tr>
<tr align="center" bgcolor="#FFFFFF">
<td height="20">번호6</td>
<td><input name="num6" type="text" id="num6" size="2" maxlength="2"></td>
</tr>
<tr align="center" bgcolor="#FFFFFF">
<td height="20" colspan="2"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr align="center">
<td width="34%"><input type="submit" name="Submit" value="연속입력"></td>
<td width="13%"><input name="button" type="button" onClick="javascript:check(this.form);" value="클릭"></td>
<td width="25%"><input type="reset" name="Submit3" value="취소"></td>
<td width="28%"><input type="button" name="Submit4" value="닫기"></td>
</tr>
</table></td>
</tr>
</table>
</form>
</body>
</html>
onClick="javascript:check(this.form);" 은 없애고 스크립트의 모든 f는 lotto로 바꿔주세요.
그리고 else 에 return true;를 두고 함수 맨 마지막에는 return false;를 두세요.