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
pranavefergussonianpranavefergussonian 

Visual force and Javscript issue

Visual force and Javscript issue

Im trying to validate the visual force page using the javascript [ not the JQUERY ],

Can any one suggest a good code to validate a text box ,,,,

     General code such as

          1--document.form.field_id.value----------- THIS IS NOT WORKING.....

          2--getElementById('field_id')------------THIS IS NOT WORKING EITHER........

 

So suggest something better ...........Thanks in Advance .....

 

Regards,

Pranav

Best Answer chosen by Admin (Salesforce Developers) 
Starz26Starz26

does every element in your VF page have an ID?you may need to select it like  thepage:theform:theelement:theitem and drill down to it.

 

This issue is exaclty why I use JQUERY, much eaiser...

All Answers

SeAlVaSeAlVa

Try with 

 

getElementById('{!$component.field_id}')

 

Regards

pranavefergussonianpranavefergussonian

sorry mate ,it didn go well......

try better if possible ,thnx agaain

Starz26Starz26

does every element in your VF page have an ID?you may need to select it like  thepage:theform:theelement:theitem and drill down to it.

 

This issue is exaclty why I use JQUERY, much eaiser...

This was selected as the best answer
pranavefergussonianpranavefergussonian

I want to validate the textBox on button click ...... using JAVASCRIPT

 

SOLUTION FOR THIS PLEASE..... HOW TO VALIDATE this TxtBOX

 

<script type="text/javascript">
   function abcd()
     {
       var temp=document.getElementById('txtOrgName');
       if(temp==null||temp=='')
       {
         alert("Empty Organization Name");
         return false;
        }
     }

</script>
<apex:form id="formPranav">

            <td>Oraganization Name :</td>
            <td><apex:inputText id="txtOrgName" value="{!str_OrgName}"/></td>
</apex:form>

 

                                                            //BUTTON AS FOLLOWS

                <apex:commandButton onclick="abcd()" value="Save" action="{!save}"/>

SeAlVaSeAlVa

Try

 

<script type="text/javascript">
   function abcd()
     {
       var temp=document.getElementById('{!$component.formPranav.txtOrgName}').value;
       if(temp==null||temp=='')
       {
         alert("Empty Organization Name");
         return false;
        }
     }

</script>
<apex:form id="formPranav">
            <td>Oraganization Name :</td>
            <td><apex:inputText id="txtOrgName" value="{!str_OrgName}"/></td>
</apex:form>

 Regards

pranavefergussonianpranavefergussonian

I want to validate the textBox on button click ......

 

ANY JQUERY SOLUTION.............

 

SOLUTION FOR THIS PLEASE..... HOW TO VALIDATE this TxtBOX

 

<script type="text/javascript">
   function abcd()
     {
       var temp=document.getElementById('txtOrgName');
       if(temp==null||temp=='')
       {
         alert("Empty Organization Name");
         return false;
        }
     }

</script>
<apex:form id="formPranav">

            <td>Oraganization Name :</td>
            <td><apex:inputText id="txtOrgName" value="{!str_OrgName}"/></td>
</apex:form>

 

                                                            //BUTTON AS FOLLOWS

                <apex:commandButton onclick="abcd()" value="Save" action="{!save}"/>

SeAlVaSeAlVa

Try this

 

<script type="text/javascript">
   function abcd()
     {
       var temp=document.getElementById('{!$component.formPranav.txtOrgName}').value;
       if(temp==null||temp==''){
alert("Empty Organization Name");
return false;
}else{
return true;
}
}
</script>
<apex:form id="formPranav">
<td>Oraganization Name :</td>
<td><apex:inputText id="txtOrgName" value="{!str_OrgName}"/></td>
</apex:form>

 

and this for the button

 

<apex:commandButton onclick="if(!abcd()) return false;" value="Save" action="{!save}"/>

 

 

Regards

Chamil MadusankaChamil Madusanka

This is a javascript solution

 

<script type="text/javascript">
   function abcd(id)
     {
       var temp=document.getElementById(id).value;
       if(temp==null||temp=='')
       {
         alert("Empty Organization Name");
         return false;
        }
		else
		{
			validatedAction();
		}
     }

</script>
<apex:form id="formPranav">
<apex:actionFunction name="validatedAction" action="{!save}" />
            <td>Oraganization Name :</td>
            <td><apex:inputText id="txtOrgName" value="{!str_OrgName}"/></td>
</apex:form>

<apex:commandButton onclick="abcd('{!$Componenet.txtOrgName}')" value="Save" />

 For more refer : http://www.salesforceworld.blogspot.com/2011/06/javascript-with-visualforce-pages.html

                              http://www.salesforceworld.blogspot.com/2011/06/parameter-passing-using.html

 

If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.