Archive for 七月, 2007

CheckBox 全選與取消全選

JavaScript程式碼 
function SetAllCheckBoxes(FormName, CheckValue)
{
  var objForm = document.forms[FormName];
  var objLen = objForm.length;
  for (var iCount = 0; iCount < objLen; iCount++)
  {
    if (CheckValue == true)
  {
  if (objForm.elements[iCount].type == “checkbox”)
  { objForm.elements[iCount].checked = true;}
  }
  else
  {
  if (objForm.elements[iCount].type == “checkbox”)
  { objForm.elements[iCount].checked = false;}
  }
  }
}
如何使用
onclick=”SetAllCheckBoxes(‘aspnetForm’, true);”
onclick=”SetAllCheckBoxes(‘aspnetForm’, false);”

Continue reading »

Select All and Unselect All (Checkbox)_JavsScript

function SetAllCheckBoxes(FormName, FieldName, CheckValue)
{
if(!document.forms[FormName])
return;
var objCheckBoxes = document.forms[FormName].elements[FieldName];
if(!objCheckBoxes)
return;
var countCheckBoxes = objCheckBoxes.length;
if(!countCheckBoxes)
objCheckBoxes.checked = CheckValue;
else
// set the check value for all check boxes
for(var i = 0; i < countCheckBoxes; i++)
objCheckBoxes[i].checked = CheckValue;
}
//How to use this function
<input type=”button” onclick=”SetAllCheckBoxes(‘myForm’, ‘myCheckbox’, true);” value=”I like them all!”>
<input type=”button” onclick=”SetAllCheckBoxes(‘myForm’, ‘myCheckbox’, false);” value=”I don’t like any of them!”>

Continue reading »