Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mj6671's avatar
Level 1

drop-down

so I was trying to click a dropdown option of a site there is the code :

<ul class="select2-results" role="listbox" id="select2-results-8">
<li class="select2-results-dept-0 select2-result select2-result-selectable select2-highlighted" role="presentation"><div class="select2-result-label" id="select2-result-label-269" role="option">
<span class="select2-match">Good</span></div></li>
<li class="select2-results-dept-0 select2-result select2-result-selectable" role="presentation">
<div class="select2-result-label" id="select2-result-label-270" role="option">Very 
<span class="select2-match">Good</span></div></li></ul>

I have used click(), key down, key up, and event handler it only returns undefine. somehow I managed to open the drop menu but I can't click on the option Mainly they have used the input tag, not a select tag so I can't use selectedindex also not working. I am new to these topics .somebody have any idea how can we do this?:)

0 likes
6 replies
mj6671's avatar
Level 1

so I was trying to click a dropdown option of a site,I have used click(), key down, key up, and event handler it only returns undefine. somehow I managed to open the drop menu but I can't click on the option Mainly they have used the input tag, not a select tag so I can't use selectedindex also not working. I am new to these topics .somebody have any idea how can we do this?:) code is

<ul class="select2-results" role="listbox" id="select2-results-8">
<li class="select2-results-dept-0 select2-result select2-result-selectable select2-highlighted" role="presentation"><div class="select2-result-label" id="select2-result-label-269" role="option">
<span class="select2-match">Good</span></div></li>
<li class="select2-results-dept-0 select2-result select2-result-selectable" role="presentation">
<div class="select2-result-label" id="select2-result-label-270" role="option">Very 
<span class="select2-match">Good</span></div></li></ul>
gych's avatar

Can you also share the js code you're using for the dropdown functionality?

1 like
mj6671's avatar
mj6671
OP
Best Answer
Level 1

@gych To open the options and enter the value, I'm using:

const input =document.querySelector("#s2id_autogen8") #input box id 
input.value = 'Good' #option need to search on dropdown 

const event = new Event('input', {
  bubbles: true,
  cancelable: true,
})

input.dispatchEvent(event)

also, I have tried using "change" not working for selecting an option

1 like

Please or to participate in this conversation.