function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Mona Lisa 9Mona Lisa 9 

when checkbox field is marked as true at that instant ,display an alert message(popup with some text) before pressing save button

I want to display an alert message at the instant when the checkbox is ticked. I had a VF code but the problem was- alert message display only after clicking standard save button. Plz, help me on this issue.

    <apex:page standardController="Opportunity" rendered="{!(Opportunity.Forecast_Indicator__c)}">
        <script type="text/javascript">
            window.alert("Text");
        </script>
    </apex:page>

 
Best Answer chosen by Mona Lisa 9
Sharad SoniSharad Soni
Hi Mona Lisa 9,

After looking your problem, I've created a sample code in my org that I am posting here.

<apex:page >
    <script>
    function f() {
            alert("Text");
        }
        </script>
    <apex:form>
    <apex:inputCheckbox onclick="f()" />
        </apex:form>
</apex:page>

Please mark it best answer if you find it helpful.
Thanks

All Answers

RD@SFRD@SF
Hi Mona,

1) I think your approach is not working because the value of the check box is changed only once its saved. That is why you are getting the messgae after clicking save.
2) In the form where you have the check box field in that if you put onclick='alert('Text')'.

Hope it helps
RD 
Sharad SoniSharad Soni
Hi Mona Lisa 9,

After looking your problem, I've created a sample code in my org that I am posting here.

<apex:page >
    <script>
    function f() {
            alert("Text");
        }
        </script>
    <apex:form>
    <apex:inputCheckbox onclick="f()" />
        </apex:form>
</apex:page>

Please mark it best answer if you find it helpful.
Thanks
This was selected as the best answer
Ashutosh GurjarAshutosh Gurjar
Sharad you are right,..you deserve best answer but you should mention who taught you this technique,,,so i deserve best answer.
Thanks in advance
Mona Lisa 9Mona Lisa 9
Thanks Sarad it is helpful.
ShannuShannu
here is my code, but it's not working as expected.
Could you help me here please.
<apex:page standardController="Account" rendered="{!(Account.Active_Customer__C)}">
    <script>
    function f(confirmsave) {
            alert("Text");
        }
        </script>
    <apex:form>
    <apex:inputCheckbox onclick="f(!save)" />
        </apex:form>
</apex:page>