Enable / Disable Checkbox
Posted: Wed Mar 09, 2011 3:55 pm
Hello All.
I found a little script on the internet, that basically enables and disables form items, depending upon a checkbox being selected or not.
The script is as follows
and my form is as follows
i am woundering if someone can help me change this script so that when you disable all the other checkboxs if they are checked they get unchecked. And when you come to enable them again, they can stay unchecked until the user decides to select them. Basically i want it so when you disable the checkboxes they reset back to unchecked.
Thanks
David
I found a little script on the internet, that basically enables and disables form items, depending upon a checkbox being selected or not.
The script is as follows
Code: Select all
function enableDisable(){
var disable = true;
var arglen = arguments.length;
var startIndex = 0;
var frm = document.CreateCV;//change appropriate form name
if (arglen>0){
if (typeof arguments[0]=="boolean") {
disable=arguments[0];
if (arglen>1) startIndex=1;
}
for (var i=startIndex;i<arglen;i++){
obj = eval("frm."+arguments[i]);
if (typeof obj=="object"){
if (document.layers) {
if (disable){
obj.onfocus=new Function("this.blur()");
if (obj.type=="text") obj.onchange=new Function("this.value=this.defaultValue");
}
else {
obj.onfocus=new Function("return");
if (obj.type=="text") obj.onchange=new Function("return");
}
}
else obj.disabled=disable;
}
}
}
}Code: Select all
<form id="CreateCV" name="CreateCV" action="req/createCV.php" method="post">
<label>CV Title:</label><br />
<input id="title" name="title" type="text" class="createCVinput" width="100%"/><br /><br />
<label>CV Description:</label><br />
<input id="desc" name="desc" type="text" class="createCVinput" width="100%"/><br /><br />
<u>CV Searchable Categories:</u>
<table width="100%" border="0">
<tr>
<td width="50%"><input type="checkbox" name="control1" onclick="enableDisable(this.checked,'cat1','cat2','cat3','cat4','cat5','cat6','cat7','cat8','cat9','cat10','cat11','cat12','cat13','cat14','cat15','cat16','cat17','cat18','cat19','cat20','cat21','cat22','cat23','cat24','cat25')"/><label>Exclude CV from searches</label></td>
<td></td>
</tr>
<tr>
<td width="50%"><input name="cat1" type="checkbox" value=""/><label>Administration</label></td>
<td><input name="cat2" type="checkbox" value=""/><label>IT, Economics, Statistics and Management Services </label></td>
</tr>
<tr>
<td><input name="cat3" type="checkbox" value=""/><label>Advertising, Marketing and PR</label></td>
<td><input name="cat4" type="checkbox" value=""/><label>Information Services</label></td>
</tr>
<tr>
<td><input name="cat5" type="checkbox" value=""/><label>Animal and Plant Resources</label></td>
<td><input name="cat6" type="checkbox" value=""/><label>Insurance, Pensions and Actuarial work</label></td>
</tr>
<tr>
<td><input name="cat7" type="checkbox" value=""/><label>Arts, Design and Crafts</label></td>
<td><input name="cat8" type="checkbox" value=""/><label>Law Enforcement and Public Protection </label></td>
</tr>
<tr>
<td><input name="cat9" type="checkbox" value=""/><label>Construction and Property Management</label></td>
<td><input name="cat10" type="checkbox" value=""/><label>Legal Services</label></td>
</tr>
<tr>
<td><input name="cat11" type="checkbox" value=""/><label>Counselling, Social and Guidance Services</label></td>
<td><input name="cat12" type="checkbox" value=""/><label>Leisure, Sport and Tourism</label></td>
</tr>
<tr>
<td><input name="cat13" type="checkbox" value=""/><label>Education Teaching and Lecturing</label></td>
<td><input name="cat14" type="checkbox" value=""/><label>Logistics and Transport</label></td>
</tr>
<tr>
<td><input name="cat15" type="checkbox" value=""/><label>Engineering</label></td>
<td><input name="cat16" type="checkbox" value=""/><label>Manufacturing and Processing</label></td>
</tr>
<tr>
<td><input name="cat17" type="checkbox" value=""/><label>Finance, including management consultancy</label></td>
<td><input name="cat18" type="checkbox" value=""/><label>Natural Resources and the Environment</label></td>
</tr>
<tr>
<td><input name="cat19" type="checkbox" value=""/><label>General management</label></td>
<td><input name="cat20" type="checkbox" value=""/><label>Publishing, Media and Performing Arts</label></td>
</tr>
<tr>
<td><input name="cat21" type="checkbox" value=""/><label>Health Care</label></td>
<td><input name="cat22" type="checkbox" value=""/><label>Sales, Retail and Buying</label></td>
</tr>
<tr>
<td><input name="cat23" type="checkbox" value=""/><label>Hospitality and Events Management</label></td>
<td><input name="cat24" type="checkbox" value=""/><label>Scientific Services</label></td>
</tr>
<tr>
<td><input name="cat25" type="checkbox" value=""/><label>Human Resources and Employment</label></td>
<td></td>
</tr>
</table><br />
<input name="" type="submit" value="Create CV" tabindex="3" class="createCVButton"/>
</form>Thanks
David