Why document.getElementById(“something”).value not working for <Select> with

3.1K    Asked by IshaPatil in Salesforce , Asked on Aug 17, 2021

The document.getElementById("something").value in my controller on HTML tag  is not working after Locker Service is enabled. I did console.log() and it's returning nothing.

Any idea how to overcome this issue? Any idea why document.getelementbyid not working?

Help is very much appreciated.

 

HTML markup :

<select class="form-control picklist" onchange="{!c.filteredProducts}" name="Discount__c" id="discount"> </select>

And the javascript function:

filteredProducts: function(component,event,helper) { var discount =document.getElementById("discount").value; }
Answered by Julie Baber

The reason behind document.getelementbyid not working is :


JavaScript document. getElementByID is not a function Solution. The JavaScript getElementById method selects an element from the HTML Document Object Model (DOM). If you incorrectly spell this method, you'll encounter the document.

 You can do something like this it's may help you:

  Volvo Saab Opel Audi   function changeVal(){ console.log(':::',document.getElementById("SelectId").value); }  

Your Answer

Interviews

Parent Categories