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

체크박스 체크 수 갯수 제한

페이지 정보

작성자 MintState 댓글 0건 조회 9,943회 작성일 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건 4 페이지
Javascript 목록
번호 제목 글쓴이 조회 날짜
118 MintState 10045 11-10
117 MintState 11435 11-10
116 MintState 14775 11-11
열람중 MintState 9944 11-17
114 MintState 11084 11-17
113 MintState 9853 11-17
112 MintState 10167 11-17
111 MintState 9389 11-17
110 MintState 10567 11-17
109 MintState 11805 11-17
108 MintState 13829 11-17
107 MintState 12831 11-17
106 MintState 14262 11-17
105 MintState 20172 11-17
104 MintState 13857 11-17
103 MintState 12307 11-17
102 MintState 14394 11-17
101 MintState 9629 11-17
100 MintState 11791 11-17
99 MintState 16149 11-17
게시물 검색
모바일 버전으로 보기
CopyRight ©2004 - 2024, YesYo.com MintState. ™