YesYo.com MintState Forums
뒤로    YesYo.com MintState BBS > Tech > Javascript
검색
멤버이름    오토
비밀번호 
 

체크박스 체크 수 갯수 제한

페이지 정보

작성자 MintState 댓글 0건 조회 9,947회 작성일 08-11-17 11:02

본문

체크박스 체크 수 갯수 제한

<script>
//function setCheckBoxHistory
//인자로 들어온 체크 박스들에 대한 체크 히스토리를 저장합니다.
//히스토리에서 체크 해제할 checkbox를 찾아 체크를 해제하고 새 체크 박스를 체크합니다.
function setCheckBox(NewCheck)
{

	var temp = new Array();
	var temp1,j=0;
	
//	this.History[this.History.length] = NewCheck; //히스토리에 추가합니다.
	for(var i=0; i< this.CheckLimit ; i++){
		temp1 = this.History[this.History.length - this.CheckLimit + i];
		if( temp1 && temp1 != NewCheck) {
		temp[j++] = temp1;
		}
	}//end of for

	if(temp.length) this.History = temp;

    if(this.History.length == this.CheckLimit ){ //히스토리의 수가 체킹 제한 갯수와 같을 경우.

		var DeCheck = this.History[0];
		document[this.FormName][DeCheck].checked = false;
		this.History[this.History.length] = NewCheck;

	}else{

		this.History[this.History.length] = NewCheck;
		this.History = this.History.slice(this.History.length - this.CheckLimit ,this.History.length);

	}
}//end of function



//function initCheckBoxHistory
//인자로 들어온 체크 박스들에 대한 체크 히스토리를 초기화/생성합니다.
function initCheckBoxHistory()
{
	var j=0;
	var thisArgLen=initCheckBoxHistory.arguments.length;
	var CheckBoxName;
	this.FormName = initCheckBoxHistory.arguments[0]; //폼이름
	this.CheckLimit = initCheckBoxHistory.arguments[1]; //체크는 몇개까지?
	this.History = new Array();
	this.setCheckBox = setCheckBox;

	for(var i =2; i < thisArgLen; i++){

		CheckBoxName=initCheckBoxHistory.arguments[i];
		if( document[this.FormName][CheckBoxName].checked ){
			this.History[j++] = CheckBoxName;	
		}//end of for
	}//end of for

}

function showEtc()
{
	if(document.formname.ch10.checked){

		document.formname.etc.style.display="";
		document.formname.etc.focus();

	}else{
		document.formname.etc.style.display="none";
	}

}


function init()
{
             // 인자 (폼이름,체크할 최대갯수,체크박스이름1,체크박스이름2..)
	Question1 = new initCheckBoxHistory("formname",2,"ch1","ch2","ch3","ch4","ch5","ch6","ch7","ch8","ch9","ch10");
	if(document.formname.ch10.checked) document.fr.etc.style.display="";

}
</script>

<body onload=init()>
<form name=formname>
<pre> 1 다음중 젤로 이쁜 사람 두명을 고르시오
<input type=checkbox name=ch1 value=Y onclick="Question1.setCheckBox('ch1');showEtc();"> 박지혜 <br>
<input type=checkbox name=ch2 value=Y onclick="Question1.setCheckBox('ch2');showEtc();"> 마님<br>
<input type=checkbox name=ch3 value=Y onclick="Question1.setCheckBox('ch3');showEtc();"> 곰숭이<br>
<input type=checkbox name=ch4 value=Y onclick="Question1.setCheckBox('ch4');showEtc();"> 이뿌니<br>
<input type=checkbox name=ch5 value=Y onclick="Question1.setCheckBox('ch5');showEtc();"> 겸둥이<br>
<input type=checkbox name=ch6 value=Y onclick="Question1.setCheckBox('ch6');showEtc();"> 윤양<br>
<input type=checkbox name=ch7 value=Y checked onclick="Question1.setCheckBox('ch7');showEtc();"> 박지<br>
<input type=checkbox name=ch8 value=Y onclick="Question1.setCheckBox('ch8');showEtc();"> 오윤정<br>
<input type=checkbox name=ch9 value=Y onclick="Question1.setCheckBox('ch9');showEtc();"> 우지연<br>
<input type=checkbox name=ch10 value=Y onclick="Question1.setCheckBox('ch10');showEtc();"> 기타 <input type=text name=etc style='display:none;border-width:1; border-style:dotted;'><br>
</pre>
</form>

댓글목록

등록된 댓글이 없습니다.

Total 178건 8 페이지
Javascript 목록
번호 제목 글쓴이 조회 날짜
38 MintState 10690 11-17
37 MintState 10570 11-17
36 MintState 10516 11-17
35 MintState 10499 10-30
34 MintState 10473 11-10
33 MintState 10448 11-17
32 MintState 10406 11-10
31 MintState 10353 11-10
30 MintState 10350 10-29
29 MintState 10347 11-10
28 MintState 10170 11-17
27 MintState 10153 11-17
26 MintState 10094 11-17
25 MintState 10048 11-10
24 MintState 10022 10-31
열람중 MintState 9948 11-17
22 MintState 9926 10-29
21 MintState 9914 10-31
20 MintState 9890 11-10
19 MintState 9856 11-17
게시물 검색
모바일 버전으로 보기
CopyRight ©2004 - 2024, YesYo.com MintState. ™