체크박스 질문드립니다. 정보
체크박스 질문드립니다.
본문
3개까지만 체크할수 있는 아래와 같은 소스가 있읍니다.
소스는 블루비에서 가져온 소스구요.
글쓰기 부분에서는 작동 잘 됩니다.
문제는 글수정 부분으로 들어가면 체크가 3개까지만 되야 하는데 수정 부분에서는 계속체크가 됩니다.
고수님의 도움좀 부탁드립니다.
<SCRIPT language=JavaScript>
<!--
var maxChecked = 3; //선택가능한 체크박스 갯수
var totalChecked = 0; // 설정 끝
function CountChecked(field) {
if (field.checked)
totalChecked += 1;
else
totalChecked -= 1;
if (totalChecked > maxChecked) {
alert ("최대"+maxChecked+"개 까지만 가능합니다.");
field.checked = false;
totalChecked -= 1;
}
}
function ResetCount(){
totalChecked = 0;
}
//-->
</SCRIPT>
<INPUT name=Ants onclick=CountChecked(this) type=checkbox>http://www.blueb.co.kr
<INPUT name=Bald onclick=CountChecked(this) type=checkbox>http://www.blueb.co.kr
<INPUT name=Beards onclick=CountChecked(this) type=checkbox>http://www.blueb.co.kr
<INPUT name=Bed onclick=CountChecked(this) type=checkbox>http://www.blueb.co.kr
<INPUT name=Chins onclick=CountChecked(this) type=checkbox>http://www.blueb.co.kr
<INPUT name=Flowers onclick=CountChecked(this) type=checkbox>http://www.blueb.co.kr
<INPUT name=Flying onclick=CountChecked(this) type=checkbox>http://www.blueb.co.kr
<INPUT name=Purple onclick=CountChecked(this) type=checkbox>http://www.blueb.co.kr
<INPUT name=Teeth onclick=CountChecked(this) type=checkbox>http://www.blueb.co.kr
<INPUT name=Thinking onclick=CountChecked(this) type=checkbox>http://www.blueb.co.kr
<INPUT name=Vegetables onclick=CountChecked(this) type=checkbox>http://www.blueb.co.kr
<INPUT name=Fear onclick=CountChecked(this) type=checkbox>http://www.blueb.co.kr
<INPUT name=Everything onclick=CountChecked(this) type=checkbox>http://www.blueb.co.kr
<INPUT type=submit value=Submit>
<INPUT onclick=ResetCount() type=reset value=Reset>
블루비 http://www.blueb.co.kr/blueb/javascript.php?mid=10&p=2&keyword=%EC%B2%B4%ED%81%AC%EB%B0%95%EC%8A%A4&s=1&r=view&uid=38743
소스는 블루비에서 가져온 소스구요.
글쓰기 부분에서는 작동 잘 됩니다.
문제는 글수정 부분으로 들어가면 체크가 3개까지만 되야 하는데 수정 부분에서는 계속체크가 됩니다.
고수님의 도움좀 부탁드립니다.
<SCRIPT language=JavaScript>
<!--
var maxChecked = 3; //선택가능한 체크박스 갯수
var totalChecked = 0; // 설정 끝
function CountChecked(field) {
if (field.checked)
totalChecked += 1;
else
totalChecked -= 1;
if (totalChecked > maxChecked) {
alert ("최대"+maxChecked+"개 까지만 가능합니다.");
field.checked = false;
totalChecked -= 1;
}
}
function ResetCount(){
totalChecked = 0;
}
//-->
</SCRIPT>
<INPUT name=Ants onclick=CountChecked(this) type=checkbox>http://www.blueb.co.kr
<INPUT name=Bald onclick=CountChecked(this) type=checkbox>http://www.blueb.co.kr
<INPUT name=Beards onclick=CountChecked(this) type=checkbox>http://www.blueb.co.kr
<INPUT name=Bed onclick=CountChecked(this) type=checkbox>http://www.blueb.co.kr
<INPUT name=Chins onclick=CountChecked(this) type=checkbox>http://www.blueb.co.kr
<INPUT name=Flowers onclick=CountChecked(this) type=checkbox>http://www.blueb.co.kr
<INPUT name=Flying onclick=CountChecked(this) type=checkbox>http://www.blueb.co.kr
<INPUT name=Purple onclick=CountChecked(this) type=checkbox>http://www.blueb.co.kr
<INPUT name=Teeth onclick=CountChecked(this) type=checkbox>http://www.blueb.co.kr
<INPUT name=Thinking onclick=CountChecked(this) type=checkbox>http://www.blueb.co.kr
<INPUT name=Vegetables onclick=CountChecked(this) type=checkbox>http://www.blueb.co.kr
<INPUT name=Fear onclick=CountChecked(this) type=checkbox>http://www.blueb.co.kr
<INPUT name=Everything onclick=CountChecked(this) type=checkbox>http://www.blueb.co.kr
<INPUT type=submit value=Submit>
<INPUT onclick=ResetCount() type=reset value=Reset>
블루비 http://www.blueb.co.kr/blueb/javascript.php?mid=10&p=2&keyword=%EC%B2%B4%ED%81%AC%EB%B0%95%EC%8A%A4&s=1&r=view&uid=38743
댓글 전체
var totalChecked = 0; // 설정 끝
가 설정되니 또 3개가 체크 됩니다.
<? if($mod==u) {
$aa = 체크된 갯수 값 가져오기;
var totalChecked = '<?=$aa?>'; // 설정 끝
} else {
var totalChecked = 0; // 설정 끝
}
?>
체크 된 갯수값은 element(i) 와 같은 걸로 필터링 하시거나
처음 입력시 hidden 값으로 넣어 두시면 쉽게 처리 되겠죠...
새해 복 많이 받으세요
가 설정되니 또 3개가 체크 됩니다.
<? if($mod==u) {
$aa = 체크된 갯수 값 가져오기;
var totalChecked = '<?=$aa?>'; // 설정 끝
} else {
var totalChecked = 0; // 설정 끝
}
?>
체크 된 갯수값은 element(i) 와 같은 걸로 필터링 하시거나
처음 입력시 hidden 값으로 넣어 두시면 쉽게 처리 되겠죠...
새해 복 많이 받으세요
오류나네요.
kesan 님 다시한번 부탁드립니다.
아래는 현제 소스입니다.
<scRIPT language=Javascript>
<!--
var maxChecked = 3; //선택가능한 체크박스 갯수
var totalChecked = 0; // 설정 끝
function CountChecked(field) {
if (field.checked)
totalChecked += 1;
else
totalChecked -= 1;
if (totalChecked > maxChecked) {
alert ("최대 3개 까지만 가능합니다.");
field.checked = false;
totalChecked -= 1;
}
}
function ResetCount(){
totalChecked = 0;
}
//-->
</scRIPT>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<col style="width: 240px"></col><col style="width: 240px"></col><col style=""></col>
<tr>
<td class="t7"><input type=checkbox onclick=CountChecked(this) name=ext10_00 value="일조권 우수" <? if($ext10_00 == "일조권 우수") echo "checked"; ?> id="r11"> <label for="r11">일조권 우수</label></td>
<td class="t7"><input type=checkbox onclick=CountChecked(this) name=ext10_01 value="조망권 우수" <? if($ext10_01 == "조망권 우수") echo "checked"; ?> id="r12"> <label for="r12">조망권 우수</label></td>
<td class="t7"><input type=checkbox onclick=CountChecked(this) name=ext10_02 value="주차시설 좋음" <? if($ext10_02 == "주차시설 좋음") echo "checked"; ?> id="r13"> <label for="r13">주차시설 좋음</label></td>
</tr>
<tr>
<td class="t7"><input type=checkbox onclick=CountChecked(this) name=ext10_03 value="신혼집으로 좋은 곳" <? if($ext10_03 == "신혼집으로 좋은 곳") echo "checked"; ?> id="r14"> <label for="r14">신혼집으로 좋은 곳</label></td>
<td class="t7"><input type=checkbox onclick=CountChecked(this) name=ext10_04 value="교통환경 우수" <? if($ext10_04 == "교통환경 우수") echo "checked"; ?> id="r15"> <label for="r15">교통환경 우수</label></td>
<td class="t7"><input type=checkbox onclick=CountChecked(this) name=ext10_05 value="교육환경 우수" <? if($ext10_05 == "교육환경 우수") echo "checked"; ?> id="r16"> <label for="r16">교육환경 우수</label></td>
</tr>
<tr>
<td class="t7"><input type=checkbox onclick=CountChecked(this) name=ext10_06 value="신축 5년 미만" <? if($ext10_06 == "신축 5년 미만") echo "checked"; ?> id="r17"> <label for="r17">신축 5년 미만</label></td>
<td class="t7"><input type=checkbox onclick=CountChecked(this) name=ext10_07 value="로얄동/로얄층" <? if($ext10_07 == "로얄동/로얄층") echo "checked"; ?> id="r18"> <label for="r18">로얄동/로얄층</label></td>
<td class="t7"><input type=checkbox onclick=CountChecked(this) name=ext10_08 value="500세대이상 대단지" <? if($ext10_08 == "500세대이상 대단지") echo "checked"; ?> id="r19"> <label for="r19">500세대이상 대단지</label></td>
</tr>
<tr>
<td class="t7"><input type=checkbox onclick=CountChecked(this) name=ext10_09 value="투자가치좋음" <? if($ext10_9 == "투자가치좋음") echo "checked"; ?> id="r20"> <label for="r20">투자가치좋음</label></td>
<td class="t7"><input type=checkbox onclick=CountChecked(this) name=ext10_10 value="관리비저렴" <? if($ext10_10 == "관리비저렴") echo "checked"; ?> id="r21"> <label for="r21">관리비저렴</label></td>
<td class="t7"><input type=checkbox onclick=CountChecked(this) name=ext10_11 value="시세보다 싼 매물" <? if($ext10_11 == "시세보다 싼 매물") echo "checked"; ?> id="r22"> <label for="r22">시세보다 싼 매물</label></td>
</tr>
</table>
kesan 님 다시한번 부탁드립니다.
아래는 현제 소스입니다.
<scRIPT language=Javascript>
<!--
var maxChecked = 3; //선택가능한 체크박스 갯수
var totalChecked = 0; // 설정 끝
function CountChecked(field) {
if (field.checked)
totalChecked += 1;
else
totalChecked -= 1;
if (totalChecked > maxChecked) {
alert ("최대 3개 까지만 가능합니다.");
field.checked = false;
totalChecked -= 1;
}
}
function ResetCount(){
totalChecked = 0;
}
//-->
</scRIPT>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<col style="width: 240px"></col><col style="width: 240px"></col><col style=""></col>
<tr>
<td class="t7"><input type=checkbox onclick=CountChecked(this) name=ext10_00 value="일조권 우수" <? if($ext10_00 == "일조권 우수") echo "checked"; ?> id="r11"> <label for="r11">일조권 우수</label></td>
<td class="t7"><input type=checkbox onclick=CountChecked(this) name=ext10_01 value="조망권 우수" <? if($ext10_01 == "조망권 우수") echo "checked"; ?> id="r12"> <label for="r12">조망권 우수</label></td>
<td class="t7"><input type=checkbox onclick=CountChecked(this) name=ext10_02 value="주차시설 좋음" <? if($ext10_02 == "주차시설 좋음") echo "checked"; ?> id="r13"> <label for="r13">주차시설 좋음</label></td>
</tr>
<tr>
<td class="t7"><input type=checkbox onclick=CountChecked(this) name=ext10_03 value="신혼집으로 좋은 곳" <? if($ext10_03 == "신혼집으로 좋은 곳") echo "checked"; ?> id="r14"> <label for="r14">신혼집으로 좋은 곳</label></td>
<td class="t7"><input type=checkbox onclick=CountChecked(this) name=ext10_04 value="교통환경 우수" <? if($ext10_04 == "교통환경 우수") echo "checked"; ?> id="r15"> <label for="r15">교통환경 우수</label></td>
<td class="t7"><input type=checkbox onclick=CountChecked(this) name=ext10_05 value="교육환경 우수" <? if($ext10_05 == "교육환경 우수") echo "checked"; ?> id="r16"> <label for="r16">교육환경 우수</label></td>
</tr>
<tr>
<td class="t7"><input type=checkbox onclick=CountChecked(this) name=ext10_06 value="신축 5년 미만" <? if($ext10_06 == "신축 5년 미만") echo "checked"; ?> id="r17"> <label for="r17">신축 5년 미만</label></td>
<td class="t7"><input type=checkbox onclick=CountChecked(this) name=ext10_07 value="로얄동/로얄층" <? if($ext10_07 == "로얄동/로얄층") echo "checked"; ?> id="r18"> <label for="r18">로얄동/로얄층</label></td>
<td class="t7"><input type=checkbox onclick=CountChecked(this) name=ext10_08 value="500세대이상 대단지" <? if($ext10_08 == "500세대이상 대단지") echo "checked"; ?> id="r19"> <label for="r19">500세대이상 대단지</label></td>
</tr>
<tr>
<td class="t7"><input type=checkbox onclick=CountChecked(this) name=ext10_09 value="투자가치좋음" <? if($ext10_9 == "투자가치좋음") echo "checked"; ?> id="r20"> <label for="r20">투자가치좋음</label></td>
<td class="t7"><input type=checkbox onclick=CountChecked(this) name=ext10_10 value="관리비저렴" <? if($ext10_10 == "관리비저렴") echo "checked"; ?> id="r21"> <label for="r21">관리비저렴</label></td>
<td class="t7"><input type=checkbox onclick=CountChecked(this) name=ext10_11 value="시세보다 싼 매물" <? if($ext10_11 == "시세보다 싼 매물") echo "checked"; ?> id="r22"> <label for="r22">시세보다 싼 매물</label></td>
</tr>
</table>
<script language="javascript">
function checkCheckbox(frm,obj,num) {
var str = obj.name;
var len = frm.length;
var chk = 0;
for(i=0; i<len; i++) {
if (frm[i].name == str && frm[i].checked == true) {
chk++;
}
if (chk > num) {
alert(num + "개 까지 선택할 수 있습니다.");
obj.checked = false;
break;
}
}
}
</script>
<INPUT onClick="checkCheckbox(this.form,this,3)">숫자3은 체크가능갯수
이게 동작하려나? 한번 해보세요
function checkCheckbox(frm,obj,num) {
var str = obj.name;
var len = frm.length;
var chk = 0;
for(i=0; i<len; i++) {
if (frm[i].name == str && frm[i].checked == true) {
chk++;
}
if (chk > num) {
alert(num + "개 까지 선택할 수 있습니다.");
obj.checked = false;
break;
}
}
}
</script>
<INPUT onClick="checkCheckbox(this.form,this,3)">숫자3은 체크가능갯수
이게 동작하려나? 한번 해보세요