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
Nisar AhmedNisar Ahmed 

Displaying an custom validation error on a VF page using Javascript(not by controller).

Hi All,

 

I need to display an custom validation error message for an 'inputText' field.

For Example:

Here, I need to display an error message if the inputText for 'Name' is null or empty.

 

<div style="position:absolute; top: 145px; left: 30px;" class="cnt_popup">
Name: 
</div>
<div style="position:absolute; top: 140px; left: 105px; height:20px; width:200px;" >
     <apex:inputText id="name" value="{!Name}" styleClass="textarea" required="true">                                    
     </apex:inputText>  
</div>

 Please let me know if you have any idea about how to display an custom validation error message.

alexbalexb

Have you tried using a Validation Rule or checking the value on a Before Trigger?

Pradeep_NavatarPradeep_Navatar

You can validate inputtext value through javascript to achieve your requirement.

 

document.getElementById('{!$Component.pgVolReg:document:fstname}').value, this will give the value assigned to inputtext.

 

Here pgVolReg refer to Page id,document refer to form id and fstname refer to Input text id.

 

var fname = var fsname = Trim(document.getElementById('{!$Component.pgVolReg:document:fstname}').value);

if(fname == '' || fname == null)

{

document.getElementById('{!$Component.pgVolReg:document:fstname}').style.borderBottom ='2px solid #c00';

}