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
Faizan Ali 17Faizan Ali 17 

Event autopopulate Date/Time onClick

Hi, I hope you are well.

I would like to create something exactly the same as the standard calendar and event in SF.

Basically, whenever I click on a cell in my table it should auto-populate with the date/time.

As of now I can only make it work with a button but I would like to do it with a click.

User-added image
AnudeepAnudeep (Salesforce Developers) 
You can try calling a javascript function using onRowClick
<apex:includeScript value="{!URLFOR($Resource.jQuery, '/js/jquery-1.4.2.min.js')}"  />
<script type="text/javascript">
    $j = jQuery.noConflict();
    function clickElem(elem){
        // Add your logic here to auto populate date/time

var eventtime = '{!Event.StartDateTime + 0}';
var d = new Date(eventtime);
var dateString = d.toString();
dateString = DateUtil.getDateTimeStringFromUserLocale(d);
var ceventtime = "00N70000002bGYx=" + encodeURIComponent(dateString);

<apex:pageBlockTable value="{!account}" var="acc" onRowClick="clickElem(this);">                                    
   <apex:column headerValue="ID" value="{!acc.Id}" styleClass="accId" />
   <apex:column headerValue="Name" value="{!acc.Name}" />

Please note that this is just a sample code. I suggest making changes as per your needs

If you find this information helpful, please mark this answer as Best. It may help others in the community

ShirishaShirisha (Salesforce Developers) 
Hi Faizan,


Have you tried to use the Calendar.js plugin to achieve the requirement.Please check the below thread for the sample code:

Kindly mark it as best answer if it helps so that it can help others in the future.

Warm Regards,
Shirisha Pathuri