Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialsteve thomas
9,753 Pointswhen i type in input form, it will not display the input, instead it refresh
const form = document.getElementByID('registrar'); const input = form.querySelector('input');
form.addEventListener('submit',(e) = > { e.preventDefault();
const text=input.value; alert('text');
});
1 Answer
Jonathon Irizarry
9,154 PointsFirst of all, you need to change your document property spelling in your const form to getElementById, your 'D' is capitalized. Finally, you should take off the apostrophe marks around 'text', it should have none since it is a variable that holds your input.value (the data that you type in the input field), and make sure when you are using arrow functions in Javascript to keep the equal sign(=) and arrow sign(>) together like this (=>).
Here is how your code should look:
const form = document.getElementById('registrar');
const input = form.querySelector('input');
form.addEventListener('submit', (e) => {
e.preventDefault();
const text = input.value;
alert(text);
});