0

My script has error Uncaught TypeError: Cannot set property 'value' of null I want to set value to input

 let engine = document.querySelector('select[name=butterbean_stm_car_manager_setting_engine]');
 engine.value = "0";

How can I fix this?

HTML:

<input type="text" value name="butterbean_stm_car_manager_setting_engine" class="widefat">
Alex
  • 125
  • 6

1 Answers1

1

I dont think that the selector works, since you are selecting a select tag even though you want to grap the input tag. So maybe try

let engine = document.querySelector('input[name=butterbean_stm_car_manager_setting_engine]

instead. Though personally I would just target it with the widefat class instead since its shorter

Inkling boi
  • 53
  • 2
  • 6
  • Man, I've answered this question 32 minutes ago in the comments but you are the first one who wrote the answer so I guess I'm going to choose it as correct – Alex Apr 09 '21 at 14:18