체크박스 체크 수 갯수 제한
페이지 정보
작성자 MintState 댓글 0건 조회 10,418회 작성일 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>|
|
댓글목록
등록된 댓글이 없습니다.





체크박스 체크 수 갯수 제한