check box 정보
check box본문
대한항공 클릭후 방콕항공을 클릭하면 air2값이 false가 안됩니다.
air3가 체크 되었을때 air1,air2를 checked false 하고
값들이 정상적으로 sum 될 수 있게 부탁드립니다.
<script language ="javascript">
<!--
function check_all(s) {
var f=cnjform;
var str1=eval("f.air"+s);
var str2=eval("f.air"+(s==1?2:1));
var str3=eval("f.air"+(s==1?3:1));
f.total.value=checkChoice(str1);
if (str2.checked) {
str2.checked=false;
f.total.value=checkChoice(str2);
}
if (str3.checked) {
str3.checked=false;
f.total.value=checkChoice(str3);
}
}
function checkChoice(whichbox) {
with (whichbox.form) {
if (whichbox.checked == false)
hiddentotal.value = eval(hiddentotal.value) - eval(whichbox.value);
else
hiddentotal.value = eval(hiddentotal.value) + eval(whichbox.value);
return(formatCurrency(hiddentotal.value));
}
}
function formatCurrency(num) {
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num)) num = "0";
cents = Math.floor((num*100+0.5)%100);
num = Math.floor((num*100+0.5)/100).toString();
if(cents < 10) cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+num.substring(num.length-(4*i+3));
return (num + "원");
}
//-->
</script>
</Head>
<form name="cnjform">
<table width="793" cellpadding="0" cellspacing="0" align="center">
<tr>
<td width="793">
<div align="left">
<table width="834" border="1">
<tr>
<td width="87" height="25">
<p align="left"><font face="굴림체"><span style="font-size:12pt;"><b>항공사</b></span></font></p>
</td>
<td width="195" height="25">
<p align="left"><font face="굴림체"><span style="font-size:10pt;"><input type="checkbox" name="air1" value="1" class="cnj_input" onClick="check_all(1);">아시아나</span></font></p>
</td>
<td width="195" height="25">
<p align="left"><font face="굴림체"><span style="font-size:10pt;"><input type="checkbox" name="air2" value="2" class="cnj_input" onClick="check_all(2);">대한항공</span></font></p>
</td>
<td width="331" height="25">
<p align="left"><font face="굴림체"><span style="font-size:10pt;"><input type="checkbox" name="air3" value="3" class="cnj_input" onClick="check_all(3);">방콕항공</span></font></p>
</td>
</tr>
</table>
</div>
<div align="left">
<table width="835" border="1">
<tr>
<td width="825" height="10" colspan="6">
<p align="left"><b><span style="font-size:12pt;">관광지</span></b></p>
</td>
</tr>
<tr>
<td width="73" height="55">
<p align="center"><font face="굴림체"><span style="font-size:11pt;">방콕</span></font></p>
</td>
<td width="140" height="10">
<p><font face="굴림체"><span style="font-size:10pt;"><input type=checkbox name=Steak value="1" onClick="this.form.total.value=checkChoice(this);"></font>왕궁</span></p>
</td>
<td width="134" height="10">
<p><font face="굴림체"><span style="font-size:10pt;"><input type=checkbox name=Steak value="1" onClick="this.form.total.value=checkChoice(this);"></font>수상시장</span></p>
</td>
<td width="143" height="10">
<p><font face="굴림체"><span style="font-size:10pt;"><input type=checkbox name=Steak value="1" onClick="this.form.total.value=checkChoice(this);"></font>왓아룬</span></p>
</td>
<td width="163" height="10">
<p><font face="굴림체"><span style="font-size:10pt;"><input type=checkbox name=Steak value="1" onClick="this.form.total.value=checkChoice(this);"></font>스카이 라운지</span></p>
</td>
<td width="142" height="10">
<p><font face="굴림체"><span style="font-size:10pt;"><input type=checkbox name=Steak value="1" onClick="this.form.total.value=checkChoice(this);"></font>썬다우너스</span></p>
</td>
</tr>
</table>
<table border="1" width="836">
<tr>
<td width="154">
<p>합계</p>
</td>
<td width="666">
<p align="center"><input type="text" name="total" value="" size="23" readonly><input type=hidden name=hiddentotal value=0>
</p>
</td>
</tr>
</table>
</div>
</table>
air3가 체크 되었을때 air1,air2를 checked false 하고
값들이 정상적으로 sum 될 수 있게 부탁드립니다.
<script language ="javascript">
<!--
function check_all(s) {
var f=cnjform;
var str1=eval("f.air"+s);
var str2=eval("f.air"+(s==1?2:1));
var str3=eval("f.air"+(s==1?3:1));
f.total.value=checkChoice(str1);
if (str2.checked) {
str2.checked=false;
f.total.value=checkChoice(str2);
}
if (str3.checked) {
str3.checked=false;
f.total.value=checkChoice(str3);
}
}
function checkChoice(whichbox) {
with (whichbox.form) {
if (whichbox.checked == false)
hiddentotal.value = eval(hiddentotal.value) - eval(whichbox.value);
else
hiddentotal.value = eval(hiddentotal.value) + eval(whichbox.value);
return(formatCurrency(hiddentotal.value));
}
}
function formatCurrency(num) {
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num)) num = "0";
cents = Math.floor((num*100+0.5)%100);
num = Math.floor((num*100+0.5)/100).toString();
if(cents < 10) cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+num.substring(num.length-(4*i+3));
return (num + "원");
}
//-->
</script>
</Head>
<form name="cnjform">
<table width="793" cellpadding="0" cellspacing="0" align="center">
<tr>
<td width="793">
<div align="left">
<table width="834" border="1">
<tr>
<td width="87" height="25">
<p align="left"><font face="굴림체"><span style="font-size:12pt;"><b>항공사</b></span></font></p>
</td>
<td width="195" height="25">
<p align="left"><font face="굴림체"><span style="font-size:10pt;"><input type="checkbox" name="air1" value="1" class="cnj_input" onClick="check_all(1);">아시아나</span></font></p>
</td>
<td width="195" height="25">
<p align="left"><font face="굴림체"><span style="font-size:10pt;"><input type="checkbox" name="air2" value="2" class="cnj_input" onClick="check_all(2);">대한항공</span></font></p>
</td>
<td width="331" height="25">
<p align="left"><font face="굴림체"><span style="font-size:10pt;"><input type="checkbox" name="air3" value="3" class="cnj_input" onClick="check_all(3);">방콕항공</span></font></p>
</td>
</tr>
</table>
</div>
<div align="left">
<table width="835" border="1">
<tr>
<td width="825" height="10" colspan="6">
<p align="left"><b><span style="font-size:12pt;">관광지</span></b></p>
</td>
</tr>
<tr>
<td width="73" height="55">
<p align="center"><font face="굴림체"><span style="font-size:11pt;">방콕</span></font></p>
</td>
<td width="140" height="10">
<p><font face="굴림체"><span style="font-size:10pt;"><input type=checkbox name=Steak value="1" onClick="this.form.total.value=checkChoice(this);"></font>왕궁</span></p>
</td>
<td width="134" height="10">
<p><font face="굴림체"><span style="font-size:10pt;"><input type=checkbox name=Steak value="1" onClick="this.form.total.value=checkChoice(this);"></font>수상시장</span></p>
</td>
<td width="143" height="10">
<p><font face="굴림체"><span style="font-size:10pt;"><input type=checkbox name=Steak value="1" onClick="this.form.total.value=checkChoice(this);"></font>왓아룬</span></p>
</td>
<td width="163" height="10">
<p><font face="굴림체"><span style="font-size:10pt;"><input type=checkbox name=Steak value="1" onClick="this.form.total.value=checkChoice(this);"></font>스카이 라운지</span></p>
</td>
<td width="142" height="10">
<p><font face="굴림체"><span style="font-size:10pt;"><input type=checkbox name=Steak value="1" onClick="this.form.total.value=checkChoice(this);"></font>썬다우너스</span></p>
</td>
</tr>
</table>
<table border="1" width="836">
<tr>
<td width="154">
<p>합계</p>
</td>
<td width="666">
<p align="center"><input type="text" name="total" value="" size="23" readonly><input type=hidden name=hiddentotal value=0>
</p>
</td>
</tr>
</table>
</div>
</table>
댓글 전체
라디오로 하면 될것 같은데.. 구지 체크박스를 왜 썼을까요..?
그건 그렇고.. check_all() 함수가 아시아나 클릭했을때에만 제대로 적용되게 되어있네요..
2번이나 3번 누르면 str2, str3은 아무것도 아니지요..
if문으로 다시 풀어서 정리해놓고 살펴보셔야 할듯..
그건 그렇고.. check_all() 함수가 아시아나 클릭했을때에만 제대로 적용되게 되어있네요..
2번이나 3번 누르면 str2, str3은 아무것도 아니지요..
if문으로 다시 풀어서 정리해놓고 살펴보셔야 할듯..