Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript DOM Scripting By Example Adding and Removing Names Using the submit Event

Adlan Ilyasov
Adlan Ilyasov
2,041 Points

Im kinda lost on this one. Anyone can throw in a few examples and hints?

Im kinda lost on this one. Anyone can throw in a few examples and hints?

const form = document.querySelector('form');
const submitButton = form.querySelector('[type=Submit]');

form.addEventListener('submit', () => {

<!DOCTYPE html>
  <title>Submit Event</title>
  <input type="text" name="name">
  <input type="Submit" name="submit" value="Submit">
  <script src="app.js"></script>

2 Answers

Steven Parker
Steven Parker
218,487 Points

You might try looking at the other questions asked about this same challenge. Just be aware that not all answers are guaranteed to be correct.   :wink:

Mark Sebeck
Mark Sebeck
Treehouse Moderator 33,545 Points

Hi Adlan. Based on your code I assume you are on Task#2. So here we want to stop the default form submit behavior. If you watch the video before this challenge Gil shows you exactly what to do. You need to use the Event.preventDefault method. Also don't forget to add a event object parameter to the callback function.

Good luck and if you are still stuck be sure to post back to the community