묻고답하기
page_full_width" class="col-xs-12" |cond="$__Context->page_full_width">
폼체크 관련 질문입니다..(소스첨부)
2004.03.26 18:54
원래 php페이지인데
그냥 소스보기로 해가지구 html로 나온거 올립니다.
자바스크립트 문제이기때문에요..
문제가..
밑에 추가폼 중 셀렉트폼에서 '수정하기'를 선택하면 창이 하나뜹니다.
근데 그 창을 무시하고 '추가하기'버튼을 누르면
자바스크립트 내에서 셀렉트 value가 '수정하기'에 value인지 비교해서
체크를 하는데..
이상하게 전송이 되어버립니다.
그니까
'수정하기'로 한 상태에서 전송버튼을 누르면 전송이 안되어야 하는데 되어버립니다..
지적 부탁드립니다...
<script language="JavaScript" type="text/JavaScript">
function class_check(){
var frm = document.form;
if(frm.class_category.value == "0") {
frm.class_etc.value = "";
frm.class_etc.disabled = false;
frm.class_etc.focus();
}
else if(frm.class_category.value == "edit"){
window.open("nw.html", "editsWindow", " width=250, height=100, scrollbars=0, resizable=0");
}
else {
frm.class_etc.value = "";
frm.class_etc.disabled = true;
}
}
function ClearComma(value1){
newValue='';
for(i=0;i<value1.length;i++){
if(value1.charAt(i)!=",")
newValue = newValue + value1.charAt(i);
}
return newValue;
}
function chkInteger(Form1)
{
for( i=0 ; i < Form1.value.length ; i++ )
{
if((Form1.value.charAt(i)<'0') || (Form1.value.charAt(i)>'9'))
{
alert('숫자만 입력가능합니다.');
Form1.value=''
Form1.focus();
return false;
}
} // end for
return true;
}
function moneyShape(Moneytxt){
var money;
money = ClearComma(Moneytxt.value);
Moneytxt.value = money;
if (chkInteger(Moneytxt)){
tmpValue = '';
header = '';
if (money.charAt(0)=="-" || money.charAt(0)=="+"){
header = money.charAt(0);
money = money.substring(1,money.length);
}
if(money.length>3){
while(money.length>3){
if (tmpValue!="")
tmpValue = money.substring(money.length-3,money.length) + "," + tmpValue;
else
tmpValue = money.substring(money.length-3,money.length);
money = money.substring(0,money.length-3);
}
if(money.length>0) tmpValue = header + money +','+tmpValue;
Moneytxt.value = tmpValue;
}
}
}
var timeStr, dateStr;
function clock() {
now= new Date();
date= now.getDate();
month= now.getMonth()+1;
year= now.getYear();
dateStr= year;
dateStr+=((month < 10) ? "0" : "")+month;
dateStr+= ((date < 10) ? "0" : "") + date;
document.form.in_date.value = dateStr;
Timer= setTimeout("clock()",1000);
}
</script>
<style type="text/css">
<!--
.inputFormTb{ font-family: "돋움"; font-size: 12px; border: 2px #006666 solid}
.records{ font-family: "돋움"; font-size: 12px; color : #333366 ; border: 2px #006666 solid}
.inputBtn{ font-family: "돋움"; font-size: 11px; border: 1px #006666 solid}
.form{ font-family: "돋움"; font-size: 9pt;}
-->
</style>
<script language="JavaScript" type="text/JavaScript">
function check_submit()
{
if((!form.class_category.value)&&(form.class_category.value='edit')) {alert("분류를 선택하세요");form.class_category.focus(); return false;}
else if((form.class_category.value=="0")&&(!form.class_etc.value)) {alert("분류를 직접 입력하세요");form.class_etc.focus(); return false;}
else if(!form.money.value) {alert("금액 입력하여 주십시요.");form.money.focus(); return false;}
else if(!form.in_date.value) {alert("날짜 입력하여 주십시요.");form.in_date.focus(); return false;}
return true;
}
</script>
<table cellpadding="3" cellspacing="0" class="records" bgcolor="#00FFCC" border="1" bordercolor="#FFFFFF">
<tr><td colspan=4 bgcolor=#CCFFFF><font color=#000000 face=돋움>━┫수 입 목 록 ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━</font></td></tr>
<tr bgcolor="#00C4C4">
<td align=center width=100>분 류</td>
<td align=center width=60>금 액</td>
<td align=center width=250>내 용</td>
<td align=center width=80>날 짜</td>
</tr>
<tr bgcolor="#00ECEC">
<td align=center><font color=#FFFFFF>홈페이지제작</font></td>
<td align=right>100,000</td>
<td align=left>일하고 받은 돈입니다.</td>
<td align=center>2004 03/24</td>
</tr>
<tr bgcolor="#00ECEC">
<td align=center>회비</td>
<td align=right>200,000</td>
<td align=left>기타 의 내용입니다</td>
<td align=center>2004 03/24</td>
</tr>
<tr bgcolor="#00ECEC">
<td align=center>작업</td>
<td align=right>5,000</td>
<td align=left>회비 납입했습니다.</td>
<td align=center>2004 03/24</td>
</tr>
<br>
<form name="form" method="post" action="insert_in_Q.php" onsubmit="return check_submit();">
<table cellpadding="2" cellspacing="0" class="inputFormTb" bgcolor="#00FFCC" border="1" bordercolor="#FFFFFF">
<tr bgcolor="#00C4C4">
<td rowspan="2">
<div align="center"><b><font color="#FFFFFF">분<BR><BR>류</font></b></div>
</td>
<td rowspan="2" bgcolor="#00ECEC" width=100 style="line-height:20%">
<select name="class_category" onChange="class_check();" style="text-align:center;">
<option selected>수입분류</option>
<option>--------</option>
<option value=1>▷회비</option>
<option value=2>▷지원금</option>
<option value=3>▷작업</option>
<option value=4>▷기타</option>
<option value="0">▶직접입력</option>
<option value="edit">☞수정하기</option>
<BR><br>
<input name="class_etc" type="text" size=11 disabled>
</td>
<td>
<div align="center"><font color="#FFFFFF"><b>금액</b></font></div>
</td>
<td width="127" bgcolor="#00ECEC">
<input type="text" name="money" size="16" maxlength="10" style="text-align:right;" onkeyUp='moneyShape(this);'>
</td>
<td width="60">
<div align="center"><font color="#FFFFFF"><b>수입일자</b></font></div>
</td>
<td width="127" bgcolor="#00ECEC">
<input type="text" name="in_date" size="8" maxlength="8" onkeyUp='+ '+ 'chkInteger(this);'>
<input type="button" name="today" value="Today" class="inputBtn" onclick="clock();">
</td>
</tr>
<tr bgcolor="#00C4C4">
<td width="60">
<div align="center"><font color="#FFFFFF"><b>내역/비고</b></font></div>
</td>
<td width="127" bgcolor="#00ECEC" colspan=3>
<table width=100%>
<tr>
<td> <input type="text" name="info" size="34" maxlength="100"> </td>
<td> <input type="submit" name="submit" value="추가하기" class="inputBtn"> </td>
</tr>
</table>
</td>
</tr>
</table>
</form>
그냥 소스보기로 해가지구 html로 나온거 올립니다.
자바스크립트 문제이기때문에요..
문제가..
밑에 추가폼 중 셀렉트폼에서 '수정하기'를 선택하면 창이 하나뜹니다.
근데 그 창을 무시하고 '추가하기'버튼을 누르면
자바스크립트 내에서 셀렉트 value가 '수정하기'에 value인지 비교해서
체크를 하는데..
이상하게 전송이 되어버립니다.
그니까
'수정하기'로 한 상태에서 전송버튼을 누르면 전송이 안되어야 하는데 되어버립니다..
지적 부탁드립니다...
<script language="JavaScript" type="text/JavaScript">
function class_check(){
var frm = document.form;
if(frm.class_category.value == "0") {
frm.class_etc.value = "";
frm.class_etc.disabled = false;
frm.class_etc.focus();
}
else if(frm.class_category.value == "edit"){
window.open("nw.html", "editsWindow", " width=250, height=100, scrollbars=0, resizable=0");
}
else {
frm.class_etc.value = "";
frm.class_etc.disabled = true;
}
}
function ClearComma(value1){
newValue='';
for(i=0;i<value1.length;i++){
if(value1.charAt(i)!=",")
newValue = newValue + value1.charAt(i);
}
return newValue;
}
function chkInteger(Form1)
{
for( i=0 ; i < Form1.value.length ; i++ )
{
if((Form1.value.charAt(i)<'0') || (Form1.value.charAt(i)>'9'))
{
alert('숫자만 입력가능합니다.');
Form1.value=''
Form1.focus();
return false;
}
} // end for
return true;
}
function moneyShape(Moneytxt){
var money;
money = ClearComma(Moneytxt.value);
Moneytxt.value = money;
if (chkInteger(Moneytxt)){
tmpValue = '';
header = '';
if (money.charAt(0)=="-" || money.charAt(0)=="+"){
header = money.charAt(0);
money = money.substring(1,money.length);
}
if(money.length>3){
while(money.length>3){
if (tmpValue!="")
tmpValue = money.substring(money.length-3,money.length) + "," + tmpValue;
else
tmpValue = money.substring(money.length-3,money.length);
money = money.substring(0,money.length-3);
}
if(money.length>0) tmpValue = header + money +','+tmpValue;
Moneytxt.value = tmpValue;
}
}
}
var timeStr, dateStr;
function clock() {
now= new Date();
date= now.getDate();
month= now.getMonth()+1;
year= now.getYear();
dateStr= year;
dateStr+=((month < 10) ? "0" : "")+month;
dateStr+= ((date < 10) ? "0" : "") + date;
document.form.in_date.value = dateStr;
Timer= setTimeout("clock()",1000);
}
</script>
<style type="text/css">
<!--
.inputFormTb{ font-family: "돋움"; font-size: 12px; border: 2px #006666 solid}
.records{ font-family: "돋움"; font-size: 12px; color : #333366 ; border: 2px #006666 solid}
.inputBtn{ font-family: "돋움"; font-size: 11px; border: 1px #006666 solid}
.form{ font-family: "돋움"; font-size: 9pt;}
-->
</style>
<script language="JavaScript" type="text/JavaScript">
function check_submit()
{
if((!form.class_category.value)&&(form.class_category.value='edit')) {alert("분류를 선택하세요");form.class_category.focus(); return false;}
else if((form.class_category.value=="0")&&(!form.class_etc.value)) {alert("분류를 직접 입력하세요");form.class_etc.focus(); return false;}
else if(!form.money.value) {alert("금액 입력하여 주십시요.");form.money.focus(); return false;}
else if(!form.in_date.value) {alert("날짜 입력하여 주십시요.");form.in_date.focus(); return false;}
return true;
}
</script>
<table cellpadding="3" cellspacing="0" class="records" bgcolor="#00FFCC" border="1" bordercolor="#FFFFFF">
<tr><td colspan=4 bgcolor=#CCFFFF><font color=#000000 face=돋움>━┫수 입 목 록 ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━</font></td></tr>
<tr bgcolor="#00C4C4">
<td align=center width=100>분 류</td>
<td align=center width=60>금 액</td>
<td align=center width=250>내 용</td>
<td align=center width=80>날 짜</td>
</tr>
<tr bgcolor="#00ECEC">
<td align=center><font color=#FFFFFF>홈페이지제작</font></td>
<td align=right>100,000</td>
<td align=left>일하고 받은 돈입니다.</td>
<td align=center>2004 03/24</td>
</tr>
<tr bgcolor="#00ECEC">
<td align=center>회비</td>
<td align=right>200,000</td>
<td align=left>기타 의 내용입니다</td>
<td align=center>2004 03/24</td>
</tr>
<tr bgcolor="#00ECEC">
<td align=center>작업</td>
<td align=right>5,000</td>
<td align=left>회비 납입했습니다.</td>
<td align=center>2004 03/24</td>
</tr>
<br>
<form name="form" method="post" action="insert_in_Q.php" onsubmit="return check_submit();">
<table cellpadding="2" cellspacing="0" class="inputFormTb" bgcolor="#00FFCC" border="1" bordercolor="#FFFFFF">
<tr bgcolor="#00C4C4">
<td rowspan="2">
<div align="center"><b><font color="#FFFFFF">분<BR><BR>류</font></b></div>
</td>
<td rowspan="2" bgcolor="#00ECEC" width=100 style="line-height:20%">
<select name="class_category" onChange="class_check();" style="text-align:center;">
<option selected>수입분류</option>
<option>--------</option>
<option value=1>▷회비</option>
<option value=2>▷지원금</option>
<option value=3>▷작업</option>
<option value=4>▷기타</option>
<option value="0">▶직접입력</option>
<option value="edit">☞수정하기</option>
<BR><br>
<input name="class_etc" type="text" size=11 disabled>
</td>
<td>
<div align="center"><font color="#FFFFFF"><b>금액</b></font></div>
</td>
<td width="127" bgcolor="#00ECEC">
<input type="text" name="money" size="16" maxlength="10" style="text-align:right;" onkeyUp='moneyShape(this);'>
</td>
<td width="60">
<div align="center"><font color="#FFFFFF"><b>수입일자</b></font></div>
</td>
<td width="127" bgcolor="#00ECEC">
<input type="text" name="in_date" size="8" maxlength="8" onkeyUp='+ '+ 'chkInteger(this);'>
<input type="button" name="today" value="Today" class="inputBtn" onclick="clock();">
</td>
</tr>
<tr bgcolor="#00C4C4">
<td width="60">
<div align="center"><font color="#FFFFFF"><b>내역/비고</b></font></div>
</td>
<td width="127" bgcolor="#00ECEC" colspan=3>
<table width=100%>
<tr>
<td> <input type="text" name="info" size="34" maxlength="100"> </td>
<td> <input type="submit" name="submit" value="추가하기" class="inputBtn"> </td>
</tr>
</table>
</td>
</tr>
</table>
</form>