...

View Full Version : checkbox disabled



nikko50
10-22-2005, 11:34 PM
Hi all:)
The below script will mark all checkbox on or off. How can I get it to skip the checkboxes that are DISABLED?
Tracy

function checkAll(theForm, cName, status,el,color) {
for (i=0,n=theForm.elements.length;i<n;i++)
if (theForm.elements[i].className.indexOf(cName) !=-1) {
theForm.elements[i].checked = status;
}

}

Philip M
10-23-2005, 08:41 AM
if (formName.elements[i].disabled==true)
{
formName.elements[i].checked=false;
}

vwphillips
10-23-2005, 10:04 AM
easiest way of doing this is to assign a property to the emement when disabled
as example (just posted on another of your posts)

f40_obj.ary[f40_1].ckdisabled=true;

set this to false when disabl is removed

then in verification


function checkAll(theForm, cName, status,el,color) {
for (i=0,n=theForm.elements.length;i<n;i++)
if (theForm.elements[i].className.indexOf(cName) !=-1&&!theForm.elements[i].ckdisabled) {
theForm.elements[i].checked = status;
}

}

example snippet


..............................
}
for (f40_1=0;f40_1<f40_obj.ary.length;f40_1++){
f40_obj.ary[f40_1].ckdisabled=false;
f40_obj.ary[f40_1].removeAttribute('disabled');
}
if (f40_obj.checked==f40_state){
for (f40_2=0;f40_2<f40_obj.ary.length;f40_2++){
f40_obj.ary[f40_1].ckdisabled=true;
f40_obj.ary[f40_2].setAttribute('disabled','disabled');
}
}
f40_obj.removeAttribute('disabled');
}

function f40_AllElements(f40_){
if (f40_.all){ return f40_.all; }
return f40_.getElementsByTagName('*');
}
...............

vwphillips
10-23-2005, 10:53 AM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>
<title></title>
<script language="JavaScript" type="text/javascript">
<!--
// by Vic Phillips (23-10-2005) http://www.vicsjavascripts.org.uk
// checks if form elements are disabled
// and the element property 'ckdisabled=true' if disabled
// This property can be used in form verification to inhibit verification if true
// e.g.
// function checkAll(theForm, cName, status,el,color) {
// for (i=0,n=theForm.elements.length;i<n;i++)
// if (theForm.elements[i].className.indexOf(cName) !=-1&&!theForm.elements[i].ckdisabled) {
// theForm.elements[i].checked = status;
// }
// }
// }

// The property 'ckdisabled' must be set to property 'ckdisabled=false'
// if the element is enabled

// The utility will set all 'radio' buttons of the same name to disable="disable"
// if one 'radio' of that name is disabled.


// The utility is initialised by a <BODY> onload event
// <body onload="zxcCkDisabled('*FormID*');">
// where *FormID* = the unique ID of the form or element containing the inputs (string)

// Functional Code - No Need to Change

function zxcCkDisabled(zxcid){
zxcobj=document.getElementById(zxcid);
zxcels=zxcAllElements(zxcobj);
for (zxc0=0;zxc0<zxcels.length;zxc0++){
if (zxcels[zxc0].tagName=='INPUT'||zxcels[zxc0].tagName=='TEXTAREA'||zxcels[zxc0].tagName=='SELECT'){
if (zxcels[zxc0].getAttribute('disabled')){
if (zxcels[zxc0].disabled||zxcels[zxc0].disabled=='disabled'){
zxcels[zxc0].ckdisabled=true;
if (zxcels[zxc0].type=='radio'){
for (zxc1=0;zxc1<zxcels.length;zxc1++){
if (zxcels[zxc0].name==zxcels[zxc1].name){
zxcels[zxc1].ckdisabled=true;
zxcels[zxc1].setAttribute('disabled','disabled');
}
}
}
}
}
}
}
}

function zxcAllElements(zxc){
if (zxc.all){ return zxc.all; }
return zxc.getElementsByTagName('*');
}

//-->
</script>

</head>

<body onload="zxcCkDisabled('Form1');">
<form id="Form1" >
<input disabled="disabled" >
<select disabled="disabled" ><option>Select Box</option></select>
<input type="radio" name ="fred" disabled="disabled" >
<input type="radio" name ="fred" >
<input type="checkbox" >

</form>
</body>

</html>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum