I would like to show input text
field on radio button
selection in vanilla JavaScript.
What am I missing?
You can use event delegation on the fieldset
- whenever it observes a bubbled change
event, you know that one of the s has been selected, so you can then set the
style
of the total
input field. Use { once: true }
so that the listener only gets triggered once:
const total = document.querySelector('input[name="total"]');
document.querySelector('fieldset').addEventListener('change', () => {
total.style.display = "inherit";
}, { once: true });
input[name="total"] {
display: none;
}