글

라벨이 checkbox인 게시물 표시

Limit the number of available checkboxes in javascript / 자바스크립트로 체크할 수 있는 항목 갯수 제한하기.

<form> You can choose 2 in maximum : <input type=checkbox name=box1 id="box1" onClick="countChoices(this)"><label for=box1>Frozen</label> <input type=checkbox name=box2 id="box2" onClick="countChoices(this)"><label for=box2>Finding Nemo</label> <input type=checkbox name=box3 id="box3" onClick="countChoices(this)"><label for=box3>the Beauty and the Beast </label> </form> <input type="button" value=" Close " onClick="self.close( )"> <script> function countChoices(obj) { var max = 2; // 최대로 선택할 수 있는 박스 수 var box1 = obj.form.box1.checked;  // 사용할 체크박스 var box2 = obj.form.box2.checked; var box3 = obj.form.box3.checked; var count = (box1 ? 1 : 0) + (box2 ? 1 : 0) + (box3 ? 1 : 0); if (count > max) { alert("최대 " + max + " 개 까지만 선택할 수 있습니다"); obj.checked = false;    } } </script> ...

Select All the Checkboxs in javascript /자바스크립트로 모두선택 모두해제 하는 함수

<script> function checkall(A,B,C){ var X=eval("document.forms."+A+"."+B) for (c=0;c<X.length;c++) X[c].checked=C } </script> <form name="album"> <input type="checkbox" name="v1">Trey Songz<br> <input type="checkbox" name="v1">Adele<br> <input type="checkbox" name="v1">Sam Smith<br> <input type="checkbox" name="v1">Ed Sheeran<br> <input type="checkbox" name="v1">Coldplay<br> </form> <a href="javascript:checkall('album','v1',true)">Select All</a> <a href="javascript:checkall('album','v1',false)">Unselect All</a> ---------------------------------------------------------------------------------- Trey Songz Adele Sam Smith Ed Sheeran Coldplay...