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
XiscoXisco 

getElementById - Not working when static resource file is included

Hi All,

 

I having a trouble when getting a value from a visualforce page element. 

 

when I do this:

 

<apex:page>
  
  <apex:form id="theForm">

     <apex:pageblock id="thePageBlock" title="pageBlock">
         <apex:inputHidden id="StrTestId" value="{!Test__c.Id}"/>	
     </apex:pageblock>

  </apex:form>

  <script type="text/javascript">		
	console.log(document.getElementById('{!$Component.theForm.thePageBlock.StrTestId}').value);
  </script>

</apex:page>

 

everything works perfectly fine.... but when I create a javascript file into the static resources and I include the file into the visualforce page this stop working and the result is 'Cannot read property 'value of null' which means that getElementById is not finding the element and returns null :(

 

this is the example is giving me an this error:

 

<apex:page>
  
  <script type="text/javascript" src="{!$Resource.TestZip}/App/testGetElementId.js"></script>  

  <apex:form id="theForm">

     <apex:pageblock id="thePageBlock" title="pageBlock">
         <apex:inputHidden id="StrTestId" value="{!Test__c.Id}"/>	
     </apex:pageblock>

  </apex:form>

</apex:page>

 

Somebody have any idea why this is happening....? 

 

Thank you!

Fran.