Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. Salesforce
  3. Question
Salesforce

How can you solve getElementById Returns Null in Apex Form on Visualforce Page error effectively?

Asked by Anushri Singh Apr 23, 2021 2.2K views 1 answer
Share

About this question

I'm attempting to make a form on a Visualforce page that will, when a button is clicked, grab the contents of a SelectList and 2 InputFields and then perform some actions with those values via a function in Javascript.

However, the contents of these fields are always returned as null by document.getElementById(). I have tried using both the '{!$Component.path.to.id}' and the 'path.to.id' approaches with no luck

For privacy reasons I've obfuscated/shortened some of the code below, but I hope it will suffice:

Visualforce Page:

<!-- Override Form -->

<button type="button" class="btn btn-primary" onclick="override()" fdprocessedid="eeqbsm">Click Dat Button</button>
[removed][removed] [removed] function override(){ //grab the contents of our fields by using their unique IDs var override_plat = document.getElementById('page1.block1.form1.overr_plat'); //returns null var override_prod = document.getElementById('{!$Component.page1.block1.form1.overr_prod}'); //also returns null } [removed]

Any insight is greatly appreciated.


Your answer

1 Answer

More Salesforce discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest Salesforce Blogs

Guides, tips and career advice on Salesforce from JanBask experts.