관리 메뉴

투덜이 개발자

[jQuery] 체크박스 전체선택 배열처리. 변수 하나에 담기 본문

Program Language/JavaScript & Jquery

[jQuery] 체크박스 전체선택 배열처리. 변수 하나에 담기

엠투 2021. 11. 5. 12:50
반응형
	//$searchChkboxVal	= explode("|","A|B|C|D|E|F|G|H|I|J|K|L|M");
	$searchChkboxVal	= explode("|","B|C|D|E|F|G|H|I|J|K|L|M");​

 

<div class="item-check mt10">
<ul>
<li><label class="cr-styled"><input type="checkbox" name="MdAll" id="MdAll" value="" onclick="selectListCheck();"><i class="fa"></i>전체</label></li>
<li><label class="cr-styled"><input type="checkbox" class="checkSelect" name="select_list_set[]" value="A" onClick="search_select('A');" <? if(in_array("A",$searchChkboxVal)) { echo "checked";}?> ><i class="fa"></i>기관명</label></li>
<li><label class="cr-styled"><input type="checkbox" class="checkSelect" name="select_list_set[]" value="B" onClick="search_select('B');" <? if(in_array("B",$searchChkboxVal)) { echo "checked";}?>><i class="fa"></i>고유번호</label></li>
<li><label class="cr-styled"><input type="checkbox" class="checkSelect" name="select_list_set[]" value="C" onClick="search_select('C');" <? if(in_array("C",$searchChkboxVal)) { echo "checked";}?>><i class="fa"></i>담당자명</label></li>
<li><label class="cr-styled"><input type="checkbox" class="checkSelect" name="select_list_set[]" value="D" onClick="search_select('D');" <? if(in_array("D",$searchChkboxVal)) { echo "checked";}?>><i class="fa"></i>담당자 이메일 주소</label></li>
<li><label class="cr-styled"><input type="checkbox" class="checkSelect" name="select_list_set[]" value="E" onClick="search_select('E');" <? if(in_array("E",$searchChkboxVal)) { echo "checked";}?>><i class="fa"></i>설립년월일</label></li>
<li><label class="cr-styled"><input type="checkbox" class="checkSelect" name="select_list_set[]" value="F" onClick="search_select('F');" <? if(in_array("F",$searchChkboxVal)) { echo "checked";}?>><i class="fa"></i>담당부서/직위</label></li>
<li><label class="cr-styled"><input type="checkbox" class="checkSelect" name="select_list_set[]" value="G" onClick="search_select('G');" <? if(in_array("G",$searchChkboxVal)) { echo "checked";}?>><i class="fa"></i>참여 아동인원</label></li>
<li><label class="cr-styled"><input type="checkbox" class="checkSelect" name="select_list_set[]" value="H" onClick="search_select('H');" <? if(in_array("H",$searchChkboxVal)) { echo "checked";}?>><i class="fa"></i>대표자명</label></li>
<li><label class="cr-styled"><input type="checkbox" class="checkSelect" name="select_list_set[]" value="I" onClick="search_select('I');" <? if(in_array("I",$searchChkboxVal)) { echo "checked";}?>><i class="fa"></i>주소</label></li>
<li><label class="cr-styled"><input type="checkbox" class="checkSelect" name="select_list_set[]" value="J" onClick="search_select('J');" <? if(in_array("J",$searchChkboxVal)) { echo "checked";}?>><i class="fa"></i>담당자 전화번호</label></li>
<li><label class="cr-styled"><input type="checkbox" class="checkSelect" name="select_list_set[]" value="K" onClick="search_select('K');" <? if(in_array("K",$searchChkboxVal)) { echo "checked";}?>><i class="fa"></i>기관유형</label></li>
<li><label class="cr-styled"><input type="checkbox" class="checkSelect" name="select_list_set[]" value="L" onClick="search_select('L');" <? if(in_array("L",$searchChkboxVal)) { echo "checked";}?>><i class="fa"></i>기관 전화번호</label></li>
<li><label class="cr-styled"><input type="checkbox" class="checkSelect" name="select_list_set[]" value="M" onClick="search_select('M');" <? if(in_array("M",$searchChkboxVal)) { echo "checked";}?>><i class="fa"></i>담당자 휴대폰번호</label></li>
</ul>
</div>
	// 전체선택
	var _select_list = false;	  // 전체선택 초기화

	function selectListCheck() {
		var aform = document.theForm;
		var value;

		if( _select_list == false ) {
			value = true;
			_select_list = true;
		} else {
			value = false;
			_select_list = false;
		}

		for( i=0 ; i < aform.elements.length ; i++ ) {
			if( aform.elements[i].name == "select_list_set[]" ) {
				aform.elements[i].checked = value;
			}
		}
	}

	function search_select(v) {
		//console.log(v);
	}

	function search_submit() {

		var send_array = Array();
		var send_cnt		= 0;
		var chkbox			= $(".checkSelect");
		var searchChkboxVal	= "";	// 검색필드 선택값

		for(i=0;i<chkbox.length;i++) {
			if (chkbox[i].checked == true){
				send_array[send_cnt] = chkbox[i].value;

				if (i == 0) {
					searchChkboxVal	+= chkbox[i].value;
				} else {
					searchChkboxVal	+= "|" + chkbox[i].value;
				}

				send_cnt++;
			}
		}

		//$("#array").val(send_array);


		console.log(searchChkboxVal);
		console.log(send_array);

		console.log('search_submit();');
반응형

'Program Language > JavaScript & Jquery' 카테고리의 다른 글

한글 입력 방지  (0) 2021.11.11
부트스트랩 모달창 열고 닫기  (0) 2021.11.09
[jquery] datepicker 특정일만 선택  (0) 2021.10.28
[jQuery] radio button 제어, 사용법  (0) 2021.09.16
Swipe  (0) 2021.07.13