let input = select.querySelector(".select-input");
...
input.value = option.dataset.val;
<body>
<select>
<option>1</option>
<option>2</option>
</select>
<input class="select-input" type="hidden"/>
<script>
const select = document.querySelector('select')
const hiddenInput = document.querySelector('.select-input')
const hiddenInputEvent = new InputEvent('change')
select?.addEventListener('change', e => {
hiddenInput.value = e.target.value
hiddenInput.dispatchEvent(hiddenInputEvent)
})
hiddenInput?.addEventListener('change', e => {
console.log(hiddenInput.value)
})
</script>
</body>
const select = document.querySelector('select')
const hiddenInput = document.querySelector('.select-input')
if(select && hiddenInput){
select.onchange = (e) => {
hiddenInput.value = e.target.value
hiddenInput.onchange?.()
}
hiddenInput.onchange = (e) => {
console.log(hiddenInput.value)
}
}