Checkbox Overview

[Total: 0    Average: 0/5]

Syntax:

Body Code:

<form name=exf1>
<input type=checkbox name=c1 value="one" onclick="doIt()">1<BR>
<input type=checkbox name=c1 value="two" checked onclick="doIt()">2<BR>
</form>
<script type=text/javascript>
function doIt() {
  var _checkedItems = "";
  var _checkedValues = "";
  var _defaultChecked = "";
  var _values = new Array();
  for (var _i=0;_i<document.exf1.c1.length;_i++) {
    if (document.exf1.c1[_i].defaultChecked) {
	  _defaultChecked = " "+_i;
	}
    if (document.exf1.c1[_i].checked) {
	  _checkedItems += " "+_i;
	  _checkedValues += " "+ document.exf1.c1[_i].value;
	}
  }
  if (_checkedItems == "") _checkedItems = " [None Checked]";
  var _m1 = "Items Checked (array indexes):"+_checkedItems;
  if (_checkedValues == "") _checkedValues = " [None Checked]";
  var _m2 = "Values Of Items Checked:"+_checkedValues;
  var _m3 = "Index Of default-Checked Item: "+(_defaultChecked==""?"[None Default Checked]":_defaultChecked);
  alert(_m1+"n"+_m2+"n"+_m3);
}
</script>

Times Viewed: 1

Leave a Reply

Your email address will not be published. Required fields are marked *