If you are using PM 2.X, then you can use this JavaScript code:
Code: Select allfunction removeCheckgroupOption(checkgroupId, constantOptionValue, optionValueToRemove) {
//use the value of an option in the checkgroup that will always exist
var aNodes = getField(checkgroupId+"]["+constantOptionValue).parentNode.childNodes;
if (aNodes.length == 0) {
alert("removeCheckgroupOption() error:\ncheckgroupId '"+checkgroupId+"' or constantOptionValue '"+constantOptionValue+"' does not exist.");
return -1;
}
//find the option in the list that you want to delete:
for (i = 0; i < aNodes.length; i++) {
if (aNodes[i].id == "form["+checkgroupId+"]["+optionValueToRemove+"]") {
//remove <BR>:
aNodes[i].parentNode.removeChild(aNodes[i+2]);
//remove span and its child label:
aNodes[i+1].removeChild(aNodes[i+1].lastChild);
aNodes[i+1].parentNode.removeChild(aNodes[i+1]);
//remove input type=checkbox:
aNodes[i].parentNode.removeChild(aNodes[i]);
return 0;
}
}
//for some reason this is still executing, even when the optionValueToRemove exists:
//alert("removeCheckgroupOption() error:\nOption '"+optionValueToRemove+"' does not exist.");
return -2;
}
removeCheckgroupOption("selectServices", "accounting", "catering");
function appendCheckgroupOption(checkgroupId, constantOptionValue, newOptionValue, newOptionLabel) {
var newOptionHtml = '<input id="form['+checkgroupId+']['+newOptionValue+']" pmfieldtype="checkgroup" '+
'name="form['+checkgroupId+'][]" value="'+newOptionValue+'" type="checkbox">'+
'<span class="FormCheck"><label for="form['+checkgroupId+']['+newOptionValue+']">'+newOptionLabel+'</label></span><br>';
getField(checkgroupId+"]["+constantOptionValue).parentNode.innerHTML += newOptionHtml;
}
appendCheckgroupOption("selectServices", "accounting", "mafia", "Corporate warfare");
Here is a sample process to test it:
(8.25 KiB) Downloaded 481 times