How can I run a javascript function when a dropdownlist get focus?

I want to run a javascript function when a dropdownlist get focus. I tried a few things like:
document.getElementById("DropDownListId_hidden").addEventListener("focus", isExistingGroup);
    and
document.getElementById("DropDownListId").addEventListener("focus", isExistingGroup);
   
This works for an ejs-textbox but not for an ejs-dropdownlist.

Any suggestions?

thanks
Peter
Below an image of the dropdown that I want to start a function when getting focus.


1 Reply 1 reply marked as answer

VS Vignesh Srinivasan Syncfusion Team January 18, 2021 07:59 AM UTC

Hi Peter, 
 
We can able to run the JavaScript function when component in focus using the focus event. Please find the code example below. 
 
<ejs-dropdownlist id="default" dataSource="@ViewBag.data" placeholder="Select a game" index="2" popupHeight="220px" focus="onFocus" > 
    <e-dropdownlist-fields text="Game" value="Id"></e-dropdownlist-fields> 
</ejs-dropdownlist> 
 
<script> 
 
function onFocus() { 
//Triggers when the compnent get focus 
}  
</script> 
 
Kindly check with the above code. Please get back to us if you need further assistance. 
 
Regards, 
 
Vignesh Srinivasan.  


Marked as answer
Loader.
Up arrow icon