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

체크박스 체크 수 갯수 제한

페이지 정보

작성자 MintState 댓글 0건 조회 9,961회 작성일 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건 2 페이지
Javascript 목록
번호 제목 글쓴이 조회 날짜
158 MintState 9928 10-31
157 MintState 9943 10-29
열람중 MintState 9962 11-17
155 MintState 10037 10-31
154 MintState 10063 11-10
153 MintState 10104 11-17
152 MintState 10163 11-17
151 MintState 10184 11-17
150 MintState 10361 10-29
149 MintState 10364 11-10
148 MintState 10365 11-10
147 MintState 10424 11-10
146 MintState 10466 11-17
145 MintState 10486 11-10
144 MintState 10517 10-30
143 MintState 10537 11-17
142 MintState 10583 11-17
141 MintState 10709 11-17
140 MintState 10733 10-29
139 MintState 10794 10-29
게시물 검색
모바일 버전으로 보기
CopyRight ©2004 - 2024, YesYo.com MintState. ™