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
Nandhini S 3Nandhini S 3 

How to display default values in <apex:input text> tag?

I have a requirement to display username format in the username field.
ex: Username: <abc@abc.com>
Username field should have a default value which shows the format the user should enter. I'm not able to do that...can someone help out here.
<apex:pageMessages id="error"/> <label>Username</label> <apex:inputText value="{! username }" onkeypress="return noenter(event)" styleClass="input r4 wide mb16 mt8 username"/>
 
Best Answer chosen by Nandhini S 3
{tushar-sharma}{tushar-sharma}
I believe you need placeholder here:
<apex:inputText value="{! username }" onkeypress="return noenter(event)" html-placeholder="abc@abc.com" styleClass="input r4 wide mb16 mt8 username"/>

If this answer helps you, please mark it as accepted.

Regards,
Tushar Sharma
https://newstechnologystuff.com/

All Answers

AbhishekAbhishek (Salesforce Developers) 
Hi,

Below is the sample Example for your requirement.
 
Visualforce Page:


<apex:page controller="defaultvalue">
    <apex:inputText value="{!strDefault}"/>
</apex:page>


Apex Class:

Public class defaultvalue{
    Public string strDefault {get; set;}
    public defaultvalue(){
        strDefault = 'Test Default';
    }
}


I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks.
{tushar-sharma}{tushar-sharma}
I believe you need placeholder here:
<apex:inputText value="{! username }" onkeypress="return noenter(event)" html-placeholder="abc@abc.com" styleClass="input r4 wide mb16 mt8 username"/>

If this answer helps you, please mark it as accepted.

Regards,
Tushar Sharma
https://newstechnologystuff.com/
This was selected as the best answer