Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

I have a checkbox field, and i want if user checks that field then it should ask are you sure,if press ok then it should continue otherwise not?

share|improve this question
1  
By 'continue', do you mean it should cause a controller action to fire, or you do you mean it should just control whether or not the checkbox gets checked? –  LaceySnr Feb 6 '13 at 5:10
    
By continue I mean that checkbox which which was checked should remain checked otherwise if user selects no then checkbox should be unchecked –  sunny kapoor Feb 6 '13 at 5:59
add comment

2 Answers 2

you should call a javascript function on checkbox's onclick event like mentioned below -

onclick="if(confirm( 'Are you sure?')){ return true; } else {return false;};"
share|improve this answer
    
still not getting the msg after adding that page in the layout –  sunny kapoor Feb 6 '13 at 12:41
add comment

You can do this as follows:

      <apex:inputCheckBox value="{!Contact.Apex_Context__c}" 
           onchange="if ( (this.checked) && (!confirm('Are you sure?')) ){this.checked=false}"/>

A couple of points to note:

(1) I've assumed you only want the confirmation when the user checks the box, not when they clear it. (2) I've only tested this in chrome.

share|improve this answer
    
not working I added this visualforce page in the layout by keeping this in form tag,but when I checked the checkbox,no msg is displayed. –  sunny kapoor Feb 6 '13 at 12:38
    
This worked for me in chrome - what browser are you using? Also, when you say you added the VF page in the layout - are you expecting this to interact with a checkbox on a standard page? –  Bob Buzzard Feb 6 '13 at 12:41
    
I am using chrome, and yes i want it to interact with the standard page here is the code: <apex:page standardController="custom object"> <apex:form> <apex:inputCheckBox value="{!Custom obj.custom field}" onchange="if ( (this.checked) && (!confirm('Are you sure?')) ){this.checked=false}"/> </apex:form> </apex:page> –  sunny kapoor Feb 6 '13 at 13:01
    
The visualforce is disconnected from the standard page. If you check the box on the standard page, that won't have any effect on the visualforce elements. –  Bob Buzzard Feb 6 '13 at 13:07
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.