Find your content:

Search form

You are here

CheckBox to Populate a Date/Time Field


Hi I created a Visual force page for opportunities and displayed check box what I am looking after if checkbox == true then a date/Time field in opportunity need to populate with today's date.

Can anybody help me out with some sample piece of code please

Attribution to: rakesh

Possible Suggestion/Solution #1

Apex method:

public Opportunity oop { get; set; }
public Boolean myCheckbox { get; set; }

// Constructor
public YourClass()
    // Defaulf value of the checkbox
    myCheckbox = false;

public PageReference setDatetime()
        oop.MyDatetime__c =;
        oop.MyDatetime__c = null;

    return null;


<apex:inputCheckbox value="{!myCheckbox}">
    <apex:actionSupport event="onchange" reRender="none" action="{!setDatetime}"/>

Attribution to: Sergej Utko

Possible Suggestion/Solution #2

What you are trying to do is quite common, I have few articles about this topic. I think the closest to what you are looking for is:

Attribution to: Andres Perez
This content is remixed from stackoverflow or stackexchange. Please visit

My Block Status

My Block Content