You need to sign in to do that
Don't have an account?
Alex Wong 4
How can I show/ hide a div when the checkbox is selected?
In my case, I want to show pessage with a div, when a checkbox is checked. But when it is unchecked, I want to hide the div. I can it by using javascript, but it failed. Is there any problem for the script?
Thank you so much.
<apex:page standardController="M_Pioneers__c" extensions="addPionners"> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> <script src="https://code.jquery.com/jquery-1.10.2.js"></script> </head> <apex:form > <script> $(".showp").hide(); $("#checkbox").click(function() { if($(this).is(":checked")) { $(".showp").show("slow"); } else { $(".showp").hide("slow"); } }); </script> <apex:pagemessages /> <div> <label for="M_Pioneers_Name__c">Name</label> <apex:inputField value="{!pioneers.M_Pioneers_Name__c}" id="M_Pioneers_Name__c"/> </div> <div> <label for="M_Pioneers_Email__c">Email</label> <apex:inputField value="{!pioneers.M_Pioneers_Email__c}" id="M_Pioneers_Email__c"/> </div> <div> <label for="M_Pioneers_Phone__c">Contact Number</label> <apex:inputField value="{!pioneers.M_Pioneers_Phone__c}" id="M_Pioneers_Phone__c"/> </div> <div> <apex:inputCheckbox id="checkbox" onfocus="showp()"/> </div> <div class="showp" style="display: none"> <p>HI!</p> </div> </apex:form> </apex:page>
Thank you so much.
All Answers
Can you please wrap div with apex:outputPanel and rerender and rendered on click of checkbox change.
Please let me know, if any more information is required.
Please mark this answer as best if it helped to resolve query.
Thanks,
Pavan
rendered is something check for condition and if result comes true then its dispaly portion between tag
Rerender is something that refresh specific portion of page istead of refreshing complete page
Please refer below link for comparison
https://developer.salesforce.com/forums/?id=906F0000000AUDnIAO
I will provide sample code in few mins
I will suggest to use above simple javascript .
Please mark this as best asnswer if my reply helped.
Really thanks for your help!