Javascript Check and Uncheck All Checkboxes.

เป็น Function เล็กๆสำหรับ Check และ Uncheck ของ Checkbox ทั้งหมด โดยชื่อ Checkbox ในตัวอย่างนี้ใช้เป็น Array ครับ เหตุผลที่ใช้เพราะตอนเขียน PHP ต้องการรับค่าเป็น Array (แล้วแต่โปรแกรมที่ทำนะจ๊ะ) ดูตัวอย่างด้านล่างเลยดีกว่า

Head

<script language="JavaScript" type="text/javascript">
<!--
// - Check All Controller
function checkAllController(theForm,obj,checkName){
	if(obj.checked==true){
		eleArr=theForm.elements[checkName+'[]'];
		for (i=0;i<eleArr.length;i++){eleArr[i].checked= true ;}
	}else{
		eleArr=theForm.elements[checkName+'[]'];
		for (i=0;i<eleArr.length;i++){eleArr[i].checked= false ;}
	}
}
//-->
</script>

Body

<form action="" method="post" name="frmAdd" id="frmAdd">
<input type="checkbox" name="checkAll" id="checkAll" value="All" onclick="checkAllController(document.frmAdd,this,'checkArr')">All <br>
<input type="checkbox" name="checkArr[]" id="checkArr[]" value="1">1 <br>
<input type="checkbox" name="checkArr[]" id="checkArr[]" value="2">2 <br>
<input type="checkbox" name="checkArr[]" id="checkArr[]" value="3">3 <br>
<input type="checkbox" name="checkArr[]" id="checkArr[]" value="4">4 <br>
<input type="checkbox" name="checkArr[]" id="checkArr[]" value="5">5 <br>
</form>

Demo : http://www.memo8.com/lab/javascript/javascript-check-uncheck-all-checkboxes/demo.html
Download : http://www.memo8.com/lab/javascript/javascript-check-uncheck-all-checkboxes/demo.htmls

You can leave a response, or trackback from your own site. Responses are currently closed, but you can trackback from your own site. You can skip to the end and leave a response. Pinging is currently not allowed. Both comments and pings are currently closed.
Powered by WordPress | Shop Free T-Mobile Phones Online | Thanks to Verizon Phones without Contract, MMORPG Games and Sell Car