0

i can't get input value when changed by select

how i get input value?

thank you

 /* file script 1 */
    var select = document.getElementById('select');
    
    select.onchange=(e)=>{
        const val = e.target.value ;
        input.value=val;
         
    }
    
    /* file script 2 */
    
    var input = document.getElementById('input');
    
    input.onchange= (e)=>{
        console.log(e.target.value);
    }
Nugraha
  • 23
  • 2

1 Answers1

0

First of all, input has no onchange attribute, use oninput instead and after you change the value of the input field just call oninput:

select.onchange = (e) => {
    const val = e.target.value ;
    input.value=val;
    input.oninput();
}

input.oninput = (e) => {
    console.log(e.target.value);
}
0brine
  • 450
  • 5
  • 18