Document.getElementById is not obtaining the value of input type=text [closed]

393    Asked by Ayushigupta in Salesforce , Asked on Jul 15, 2021

In this stripped down VF page, I have 2 standard inputs. I'm trying to get the value of the "testme" input from JS, but the 2nd alert never shows.

Am I missing something? VisualForce:

 [removed] function SetLaunchD() { alert('ddate is...'); var ddate = document.getElementById('testme').val(); alert(ddate); } [removed]  test input <input type="text" id="testme"> random input box <input type="Text" id="d2" value="" size="10" onblur="SetLaunchD();">  

How do I fix document getElementById is not a function?

Answered by Cameron Oliver

Reason of getting error document getelementbyid is not a function :


Probably you have used the incorrect case for the document. getElementByID selector. Instead of using an uppercase I and a lowercase d, you have used an uppercase I and D. JavaScript does not register our program as calling the getElementById function because the function name is case sensitive.

You need to use var ddate = document.getElementById('testme').value; instead as val() is a jquery-function and not available in native javascript.

Your Answer

Interviews

Parent Categories