You need to sign in to do that
Don't have an account?
DavidGen
I can not save changes on checkboxes
Hi,
I'm creagint a VF with ten input elements of type checkbox. I'm adding a javascript that creates dependencies between checkboxes. This work well and automatic checks are visible, but when I press save button, these changes are not saved. Any Solution?
Thanks in advance.
I just discovered that you can not get the value of a disabled field . Thanks anyway.
All Answers
My VF's sample code (3 checkboxes):
<apex:page standardController="object__c" extensions="newObject" id="j_id0">
<apex:pageBlockSection title="Checkboxes" id="Block2" columns="2">
<apex:inputField id="CIA_CHECK1__c" value="{!object.CIA_CHECK1__c}"/>
<apex:inputField id="CIA_CHECK2__c" value="{!object.CIA_CHECK2__c}"/>
<apex:inputField id="CIA_CHECK3__c" value="{!object.CIA_CHECK3__c}"/>
</apex:pageBlockSection>
<script languaje="javascript">
{
var checkbox1= "j_id0:Block2:CIA_CHECK1__c";
var checkbox2= "j_id0:Block2:CIA_CHECK2__c";
var checkbox3= "j_id0:Block2:CIA_CHECK3__c";
document.getElementById(checkbox1).onchange = function(evt){ update_checks()};
document.getElementById(checkbox2).onchange = function(evt){ update_checks()};
document.getElementById(checkbox3).onchange = function(evt){ update_checks()};
function enable(id){
document.getElementById(id).disabled = false;
}
function disable(id){
document.getElementById(id).disabled = true;
}
function check(id){
document.getElementById(id).checked = true;
document.getElementById(id).value = 1;
}
function uncheck(id){
document.getElementById(id).checked = false;
document.getElementById(id).value = 0;
}
function enableAll(){
enable(checkbox1);
enable(checkbox2);
enable(checkbox3);
}
function update_checks(){
enableAll();
if (document.getElementById(checkbox1).checked === true){
disable(checkbox2);
disable(checkbox3);
uncheck(checkbox2);
check(checkbox3);
}
if(document.getElementById(checkbox2).checked === true){
disable(checkbox1);
disable(checkbox3);
uncheck(checkbox3);
check(checkbox1);
}
update_checks();
}
</script>
</apex:page>
<script languaje="javascript"> ?
I already know that <script type="text/javascript"> is now the correct form but, because language="javascript" is deprecated does not mean that it will not work.
Thanks.
If you can explain me the use case, I might be able to come up with a better solution - this looks like awfully lots of javscript...
You're right. But right now my only problem is that when I activate checkbox1, javascript must be enabled checkbox3 e.g. However when I push "save" button, I look record and no checkbox is enabled.
See code... overall, have you tried to open page in firefox and see what webdeveloper panel says? ctrl+shft+K
Maybe you are getting some kind of a validation error on save? Try including <apex:messages/> at the top of the page to make sure any error messages are displayed.
I just discovered that you can not get the value of a disabled field . Thanks anyway.