You need to sign in to do that
Don't have an account?
Jayesh Babu A V
get <apex:input> value on button click
I have created a datepicker inside the visualforce page and I want to get value of the <apex:input> into a variable, and access it on buton click. this is the code:
And this is the apex class
<apex:page docType="html-5.0" showHeader="false" controller="ShowResourcesClass" > <apex:form > <apex:pageBlock > <apex:pageBlockSection > <apex:pageBlockSectionItem > Date: <apex:input type="date" value="{!chosenDate}"/> </apex:pageBlockSectionItem> </apex:pageBlockSection> </apex:pageBlock> </apex:form> <apex:form > <apex:commandButton action="{!getDateFun}" value="Submit" id="theButton"/> </apex:form> </apex:page>
And this is the apex class
public class ShowResourcesClass { public Date chosenDate {get;set;} public void getDateFun() { System.debug('DATE: ' + chosenDate); } }Here, when I click the buttton even after choosing the date, the value of `chosenDate` is always null.
Can you verify if chosenDate displays any value when it is placed inside the constructor? Also, can you try using onclick on apex:input itself. This component supports HTML pass-through attributes using the "html-" prefix. Pass-through attributes are attached to the generated <input> tag so try passing the attributes as showing in the references below
Reference:
https://developer.salesforce.com/docs/atlas.en-us.224.0.pages.meta/pages/pages_html_features_pass_through_attributes.htm
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_input.htm
If you find this answer helpful, please mark this as solved by selecing this as Best Answer so that it may help others in the community. Thank You!
Anudeep