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
Mitesh Saparia 8Mitesh Saparia 8 

custom DatePicker not getting value in database?

<apex:page standardController="Contact" extensions="datepickerController" docType="html-5.0" >
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css"/>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.3.0/css/datepicker.css"/>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.3.0/js/bootstrap-datepicker.js"></script>
    
    <script>
        $(function () {
            $("#datepicker").datepicker({ 
                format: "dd/mm/yyyy",
                autoclose: true, 
                todayHighlight: true
            }).datepicker().val();
        });
        function getValues(element){
            console.log(element.value);
        }
    </script>
    <apex:pageMessages />
    <apex:sectionHeader title="Date Picker" subtitle="Create Contact" />
    <apex:form id="frm">   
        <apex:pageblock title="Contact" id="pb">
            <apex:pageBlockButtons >
                <apex:commandButton value="Save" action="{!save}"/>
                <apex:commandButton value="Cancel" action="{!Cancel}" />
            </apex:pageBlockButtons>
            <apex:pageBlockSection id="pbs">
                <apex:inputField value="{!Contact.Salutation}" />
                <apex:inputField value="{!Contact.FirstName}" />
                <apex:inputField value="{!Contact.LastName}" />                
                <apex:inputField value="{!Contact.Birthdate}" />  
                Birthday :--- <input type="text" id="datepicker" onchange = "getValues(this);" value="{!Contact.Birthdate}" />
                <apex:pageBlockSectionItem >
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection>
            
        </apex:pageblock>
    </apex:form>
</apex:page>
Puneet_MishraPuneet_Mishra
You have 2 Birthdate fields, what are you trying to achieve, can you elaborate?
Puneet_MishraPuneet_Mishra

if I am not wrong then you are trying to populate the contact.BirthDate field? 

if that's is right then first thing you have to change the date format from dd//mm/yyyy to mm/dd/yyyy.

then in on change add following code 

document.getElementById('{!$Component.frm:pb:pbs:contactBDate}').value=element.value;

<apex:page standardController="Contact" docType="html-5.0" >
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css"/>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.3.0/css/datepicker.css"/>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.3.0/js/bootstrap-datepicker.js"></script>
    
    <script>
        $(function () {
            $("#datepicker").datepicker({ 
                format: "mm/dd/yyyy",
                autoclose: true, 
                todayHighlight: true
            }).datepicker().val();
        });
        function getValues(element){
            document.getElementById('{!$Component.frm:pb:pbs:contactBDate}').value=element.value;
            console.log(element.value + '  == ' + document.getElementById('{!$Component.frm:pb:pbs:contactBDate}').value);
        }
    </script>
    <apex:pageMessages />
    <apex:sectionHeader title="Date Picker" subtitle="Create Contact" />
    <apex:form id="frm">   	
        <apex:pageblock title="Contact" id="pb">
            <apex:pageBlockButtons >
                <apex:commandButton value="Save" action="{!save}"/>
                <apex:commandButton value="Cancel" action="{!Cancel}" />
            </apex:pageBlockButtons>
            <apex:pageBlockSection id="pbs">
                <apex:inputField value="{!Contact.Salutation}" />
                <apex:inputField value="{!Contact.FirstName}" />
                <apex:inputField value="{!Contact.LastName}" />                
                <apex:inputField value="{!Contact.Birthdate}" id="contactBDate"/>  
                Birthday :--- <input type="text" id="datepicker" onchange = "getValues(this);" value="{!Contact.Birthdate}" />
                <apex:pageBlockSectionItem >
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection>
            
        </apex:pageblock>
    </apex:form>
</apex:page>