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
vajralavajrala 

How to display the javascript error messages below the inputField

I applied client side validations by using javascript Like

<script type="text/javascript">
        var rname=/^([A-Za-z]\s?)+(\w\s?)*$/;
        var rphone=/\d{10}/;
        var remail=/^([a-z]+\w*)+\@+([a-z]+\w*)+\.+([a-z]*)$/;
        var rcity=/^[A-Za-z]*$/;
        var rstate=/^[A-Za-z]*$/;
        var rcountry=/^[A-Za-z]*$/;
        ErrorText='';
        function myfunction(){
            var sfname=document.getElementById('{!$Component.myform.entry.Patient_entry_section:pafname}').value;
            var slname=document.getElementById('{!$Component.myform.entry.Patient_entry_section:palname}').value;
            var sphone=document.getElementById('{!$Component.myform.entry.Patient_entry_section:paphone}').value;
            var semail=document.getElementById('{!$Component.myform.entry.Patient_entry_section:paemail}').value;
            var saddress1=document.getElementById('{!$Component.myform.entry.Demographic_entry_section:address1}').value;
            var saddresstype=document.getElementById('{!$Component.myform.entry.Demographic_entry_section:addresstype}').value;
            var scity=document.getElementById('{!$Component.myform.entry.Demographic_entry_section:city}').value;
            var sstate=document.getElementById('{!$Component.myform.entry.Demographic_entry_section:state}').value;
            var scountry=document.getElementById('{!$Component.myform.entry.Demographic_entry_section:country}').value;
            if(sfname!=''){
                if(!rname.test(sfname))
                ErrorText+="\n        First name must be start with Alphabates and allows only single space";
            }else{
                ErrorText+="\n        First Name is Required Field it must be Non-Empty";
            }
            if(slname!=''){
                if(!rname.test(slname))
                ErrorText+="\n        Last name must be start with Alphabates and allows only single space";
            }else{
                ErrorText+="\n        Last Name is Required Field it must be Non-Empty";
            }  
            if(sphone!=''&&(!rphone.test(sphone)))
                ErrorText+="\n        Phone number must contain 10 numbers";
            if(semail!=''&&(!remail.test(semail)))
                ErrorText+="\n        Invalid Email formate";
            if(saddress1=='')
                ErrorText+="\n        Address1 is Required Field it must be Non-Empty";
            if(saddresstype=='')
                ErrorText+="\n        Address Type is Required Field it must be Non-Empty";
            if(scity!=''&&(!rcity.test(scity)))
                ErrorText+="\n        City allows only Alphabets";
            if(sstate!=''&&(!rstate.test(sstate)))
                ErrorText+="\n        State allows only Alphabets";
            if(scountry!=''&&(!rcountry.test(scountry)))
                ErrorText+="\n        Country allows only Alphabets";
            if (ErrorText!= "") {
                alert("Error :" + ErrorText);
                return false;
            }
            else{
                alert("success");
                return true;
            }
                
       }
    </script>

It show alert messages.I need disply the javascript validation messages below the input field.please giveme explanation with an example.

Navatar_DbSupNavatar_DbSup

Hi,

 

You can use the <apex:outputText>or <apex:outputLabel> below the input field and in JavaScript get the component through document.getElementById() and set the error message in it.

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

 

vajralavajrala

sir, please give me one example