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
Raj.....Raj..... 

i want to use jquery validation plugin in salesforce

i want to use jquery validation plugin in salesforce.


i name the id in salesforce but when it comes to html the id is changed.


exmp:

id="uname"

id="j_id0:login:uname"


pls help me to solve this problem i am not geting the out put

Best Answer chosen by Admin (Salesforce Developers) 
Pradeep_NavatarPradeep_Navatar

On compilation Visualforce page generates HTML which contains ID of VF component in a hierarchy fashion. Find below a sample code :

 

           <apex:page>

                     <apex:form>                   

                                             <apex:inputtext id="Utext" value="{!uname}"/>

                     </apex:form>

                    <script>

                                   alert(document.getElementById('pageid:formid:Utext').value);

                   </script>

          </apex:page>

 

          Note: PageId refers the Page id and formid refers the Form id.

All Answers

bob_buzzardbob_buzzard

You can get at the generated id using the $Component global variable.

 

This is documented in detail at:

 

http://www.salesforce.com/us/developer/docs/pages/Content/pages_variables_global.htm

Pradeep_NavatarPradeep_Navatar

On compilation Visualforce page generates HTML which contains ID of VF component in a hierarchy fashion. Find below a sample code :

 

           <apex:page>

                     <apex:form>                   

                                             <apex:inputtext id="Utext" value="{!uname}"/>

                     </apex:form>

                    <script>

                                   alert(document.getElementById('pageid:formid:Utext').value);

                   </script>

          </apex:page>

 

          Note: PageId refers the Page id and formid refers the Form id.

This was selected as the best answer
devisfundevisfun

Hi.

 

I'm not sure if this is still an issue, but the answers provided don't help.

 

I recently started using jQuery for VF pages, and here's what you need to do.

 

First, since Salesforce uses the dollar sign for other things, you have to set a variable as noConflict, like this:

 

var j$ = jQuery.noConflict();

 

What we did in our org was create a component that contained the resource and this variable declaration; here's the complete code for that component:

 

<apex:component access="global" selfClosing="true">
	<apex:includeScript value="{!$Resource.jQuery}"/>
   	<script type="text/javascript">
		var j$ = jQuery.noConflict();
    </script>
</apex:component>

 Now to reference jQuery on a page, we just add this:

 

<c:jQuery />

 

 Anyway, getting back to your issue.

 

If your Id is "thePage:theForm:thepb:thepbs:inputFirstName" then do this:

 

j$('[id$="inputFirstName"]').event();

 

where "event" is the event you want to happen.

 

You can also do searches for Ids using *, and using ^ searches for Ids that start with whatever is after the equal sign.  However, since the ending part of the Id is what's unique, the $ is what you'll use most.

 

Also, another trick:  to not have to worry about always typing the j$ rather than just $, do this for your .ready event:

 

j$(document).ready(function($){

 

Passing the dollar sign as an argument for the function means you can now do

 

$('[id$="inputFirstName"]').event();