간단한 계산프로그램을 짜봣어요.. 헌데... 그런데.. 답칸에 NaN만 뜨고 있네요. 답이 나와야 하는디..... 살펴봐주세요.
본문
오류주소는 다음과 같애요
<table border="0" cellspacing="0" cellpadding="0" width="900" align="center" >
<tr>
<td> <form name="fr" style="font-family:'돋움'; font-size:10px;">
<table border="0" cellspacing="0" cellpadding="0" width="900" align="center" class="table02">
<tr>
<td width="166" align="center" bgcolor="#F7F7F7" height="40">
<font color="#17365D">인터넷(비즈광랜)</font>
</td>
<td width="240" height="40">
<b><INPUT CHECKED type=radio id="office" name="office" onmouseout="ck_ck(this.value)" >사무실</b>
</td>
<td width="242">
<INPUT type=radio id="office" name="office" onmouseout="ck_ck(this.value)">공장
</td>
<td>
<INPUT type=radio id="office" name="office" onmouseout="ck_ck(this.value)">상가
</td>
</tr>
<tr>
<td height="40" align="center" bgcolor="#F7F7F7">
<font color="#17365D">DVR</font>
</td>
<td >
4CH <INPUT type="text" id="ch4" width="80" name="ch4" onkeyup="ck_ck(this.value)" >
대
</td>
<td >
8CH <INPUT type="text" id="ch8" width="80" name="ch8" onkeyup="ck_ck(this.value)" >
대
</td>
<td >
16CH <INPUT type="text" id="ch16" width="80" name="ch16" onkeyup="ck_ck(this.value)" >
대
</td>
</tr>
<tr>
<td height="40" align="center" bgcolor="#F7F7F7">
<font color="#17365D">카메라대수</font>
</td>
<td colspan="3">
<table border="0" cellspacing="0" cellpadding="0" width="784" align="center" class="table02">
<tr>
<td align="center" bgcolor="#F7F7F7" height="40">
실내돔적외선<INPUT type="TEXT" id="dom" name="dom" onkeyup="ck_ck(this.value)" > 대
</td>
<td align="center" bgcolor="#F7F7F7" height="40">
실외하우징돔적외선<INPUT type="TEXT" id="howjing" name="howjing" onkeyup="ck_ck(this.value)" > 대
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td height="40" align="center" bgcolor="#F7F7F7">
<font color="#17365D">모니터링</font>
</td>
<td height="40" >
<INPUT CHECKED type=radio id="easy" name="level" value="1" onclick="ck_ck(this.value)">양호
</td>
<td>
<INPUT type=radio id="normal" name="level" value="2" onclick="ck_ck(this.value)">보통
</td>
<td>
<INPUT type=radio id="hard" name="level" value="3" onclick="ck_ck(this.value)">불량
</td>
</tr>
</table>
<br>
<table border="0" cellspacing="0" cellpadding="0" width="900" align="center" class="table02">
<tr align="center" >
<td width="116" height="30" bgcolor="#E1E1E1">
<font color="blue">구분</font>
</td>
<td bgcolor="#E1E1E1">
<font color="blue">월기본요금</font>
</td>
</tr>
<tr align="center">
<td bgcolor="#F7F7F7" height="40" >
요금표
</td>
<td >
<input type="text" name="total" id="total" value="" class="button" width="120" readonly style="text-align:right">
</td>
</tr>
</table>
<script>
</tr>
<tr>
<td height="40" align="center" bgcolor="#F7F7F7">
<font color="#17365D">DVR</font>
</td>
<td >
4CH <INPUT type="text" id="ch4" width="80" name="ch4" onkeyup="ck_ck(this.value)" >
대
</td>
<td >
8CH <INPUT type="text" id="ch8" width="80" name="ch8" onkeyup="ck_ck(this.value)" >
대
</td>
<td >
16CH <INPUT type="text" id="ch16" width="80" name="ch16" onkeyup="ck_ck(this.value)" >
대
</td>
</tr>
<tr>
<td height="40" align="center" bgcolor="#F7F7F7">
<font color="#17365D">카메라대수</font>
</td>
<td colspan="3">
<table border="0" cellspacing="0" cellpadding="0" width="784" align="center" class="table02">
<tr>
<td align="center" bgcolor="#F7F7F7" height="40">
실내돔적외선<INPUT type="TEXT" id="dom" name="dom" onkeyup="ck_ck(this.value)" > 대
</td>
<td align="center" bgcolor="#F7F7F7" height="40">
실외하우징돔적외선<INPUT type="TEXT" id="howjing" name="howjing" onkeyup="ck_ck(this.value)" > 대
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td height="40" align="center" bgcolor="#F7F7F7">
<font color="#17365D">모니터링</font>
</td>
<td height="40" >
<INPUT CHECKED type=radio id="easy" name="level" value="1" onclick="ck_ck(this.value)">양호
</td>
<td>
<INPUT type=radio id="normal" name="level" value="2" onclick="ck_ck(this.value)">보통
</td>
<td>
<INPUT type=radio id="hard" name="level" value="3" onclick="ck_ck(this.value)">불량
</td>
</tr>
</table>
<br>
<table border="0" cellspacing="0" cellpadding="0" width="900" align="center" class="table02">
<tr align="center" >
<td width="116" height="30" bgcolor="#E1E1E1">
<font color="blue">구분</font>
</td>
<td bgcolor="#E1E1E1">
<font color="blue">월기본요금</font>
</td>
</tr>
<tr align="center">
<td bgcolor="#F7F7F7" height="40" >
요금표
</td>
<td >
<input type="text" name="total" id="total" value="" class="button" width="120" readonly style="text-align:right">
</td>
</tr>
</table>
<script>
var fr = document.fr; //젤 먼저...
function ck_ck() {
var ch4 = fr.ch4.value; // 각 변수들에 입력된 값 넣어줌
var ch8 = fr.ch8.value;
var ch16 = fr.ch16.value;
var dom = fr.dom.value;
var howjing = fr.howjing.value;
var easy = fr.easy.value;
var normal = fr.normal.value;
var hard = fr.hard.value;
var total = fr.total.value;
var office = fr.office.value;
var total=0;
if(fr.easy.value=="1"){
if(fr.easy.value=="1"){
total = parseInt(office) * (parseInt(ch4) + 300000) + (parseInt(ch8) * 600000) + (parseInt(ch16) * 900000) + (parseInt(dom) * 50000) + (parseInt(howjing) * 100000) ;
total = Math.floor(total/10) * 10 ;
fr.total.value = total;
}
total = Math.floor(total/10) * 10 ;
fr.total.value = total;
}
else if(fr.normal.value=="2"){
total = parseInt(office) * (parseInt(ch4) + 300000) + (parseInt(ch8) * 600000) + (parseInt(ch16) * 900000) + (parseInt(dom) * 50000) + (parseInt(howjing) * 100000) ;
total = Math.floor(total/10) * 9.5 ;
fr.total.value = total;
}
total = Math.floor(total/10) * 9.5 ;
fr.total.value = total;
}
else if(fr.hard.value=="3"){
total = parseInt(office) * (parseInt(ch4) + 300000) + (parseInt(ch8) * 600000) + (parseInt(ch16) * 900000) + (parseInt(dom) * 50000) + (parseInt(howjing) * 100000) ;
total = Math.floor(total/10) * 9 ;
fr.total.value = total;
}
total = Math.floor(total/10) * 9 ;
fr.total.value = total;
}
}
</script>
답변 2
제발 라디오랑 체크박스 타입에 기본값좀 넣으세요.
그리고 함수 호출시에 this.value는 왜 넣어서 보내나요?
함수에서 폼에서 값을 읽어 오겠금 해 놓으셨잖아요.
NaN은 숫자가 아닌값이라는 뜻이예요.
계산식에 들어가는 값이 숫자인지 체크하세요.
사무실, 공장, 상가에만 value를 넣지 않은게 아니라
아래에 체널에도 값을 안 넣으셨네요.
개발자 분이시면 다른 직업 알아 보시고, 다른 분야 분이시면 책보고 공부 좀 더 하셔야 할거 같으네요.
사무실, 공장, 상가 기본값(value)이 없네요. 라디오 타입인데...
답변을 작성하시기 전에 로그인 해주세요.