How would you set the default value of a form text field in JavaScript?
Instead of using document.getElementById()
you can now use document.querySelector()
for different cases
more info from another StackOverflow answer:
querySelector
lets you find elements with rules that can't be expressed withgetElementById
andgetElementsByClassName
EXAMPLE:
document.querySelector('input[name="myInput"]').value = 'Whatever you want!';
or
let myInput = document.querySelector('input[name="myInput"]');
myInput.value = 'Whatever you want!';
Test:
document.querySelector('input[name="myInput"]').value = 'Whatever you want!';