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
S_LieS_Lie 

JQuery and Visualforce Component

Hi,

 

I'm trying to connect JQuery with Visualforce component ( eg. Apex:InputText ), but not able to get ID in VF component to use in the JQuery function.

Please help!

 

Thanks

ConejoConejo

 

<script type="text/javascript">var userIdAuditId = jq('{!$Component.userIdAudit}');</script>


<script type="text/javascript">
      var j = jQuery.noConflict();
      
  
      function jq(myid) 
      {     
            return '#' + myid.replace(/(:|\.)/g,'\\\$1');
      }
                                            
  </script>

 

You need two things: the dom id of the vf  control:

 

 

<script type="text/javascript">var userIdAuditId = jq('{!$Component.userIdAudit}');</script>

and a function to clean up the special characters in the visualforce generated id's:


<script type="text/javascript">
      var j = jQuery.noConflict();
      
  
      function jq(myid) 
      {     
            return '#' + myid.replace(/(:|\.)/g,'\\\$1');
      }
                                            
  </script>

 

 

The script above also sets Jquery into the noConflict mode. You need this as well.

 

HTH,

 

 

Rich C.

S_LieS_Lie

 

Hi ,

 

Thanks for your reply

 

For example :

 

 <apex:form id="FormV">
     <apex:pageBlock id="BlockV" >
         <apex:pageBlockSection id="SectionV" >    
                 <apex:inputText id="target"/>
             <a href="" id="OkB">Click Here!</a>
         </apex:pageBlockSection>
     
     
     </apex:pageBlock>
</apex:form>

 

how to define the inputText id ?

 

jq('{!$Component.target}'); --> not working