You need to sign in to do that
Don't have an account?
set Date value for apex date field in javascript onload
Hi All,
I trying to set a date value for Apex date field in javascript. How to do that?
You need to sign in to do that
Don't have an account?
Hi All,
I trying to set a date value for Apex date field in javascript. How to do that?
Am supposing that you want to do this by using standardcontroller on visualforce page, try this :
Thanks
Ankit Arora
Blog | Facebook | Blog Page
All Answers
u have to use the javascript's date object like this
var myDate=new Date();..
Chamil, can you please explore more what exactly you want to do? So I can provide you the code.
Thanks
Ankit Arora
Blog | Facebook | Blog Page
Hi Ankit,
I have Date field and I have used in VF page as a <apex:inputField>. I want to set date value on page onload in javascript.
If you are using a Custom controller, or a controller extension, then instead of doing it in Javscript, you're probably better served doing it in the Controller Constructor.
If you are only using a standard controller, and you are trying to set a field on the form to a specifc data value, then you need to use the $component to get the Id of the Date field, then use standard DOM to set the value for the field with that ID. However, you might be better off setting a default value for that field in the field definition.
So, there are many answers depending on what you are trying to do. Clarify your business need before digging into a specific implementation question.
Best, Steve.
Am supposing that you want to do this by using standardcontroller on visualforce page, try this :
Thanks
Ankit Arora
Blog | Facebook | Blog Page
Instead of hard-coding the reverse-engineered dom-id as shown you should use {!$Component.dt} to get the dom-id for the component with id='dt'
When I click the "Save" button date is inserted in the model. And also I am not getting date picker in visual force page.
In Visual force Page
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!savetherecord}"/>
</apex:pageBlockButtons>
<apex:outputText >Start Date</apex:outputText>
<apex:inputText value="{!stdate}"/>
//Controller
public class MyCampaign {
public Date stdate{get;set;}
public PageReference savetherecord(){
MyCampaign__c mc = new MyCampaign__c();
mc.Start_Date__c = stdate;
PageReference pr = new PageReference('https://ap1.salesforce.com/a0D/o');
return pr;
}
Could you please hepl me