Regular User
Regular User

Reputation: 511

Cannot set property 'value' of null when setting value in input

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">

Upvotes: 0

Views: 816

Answers (1)

Inkling boi
Inkling boi

Reputation: 53

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

Upvotes: 1

Related Questions