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 trial

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

patrick shangala
patrick shangala
6,217 Points

can't understand the question someone to help me out with this problem

how can i solve this problem ?

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

submitButton.addEventListener('click', () => {
  e.preventDefualt();
});
index.html
<!DOCTYPE html>
<html>
<head>
  <title>Submit Event</title>
</head>
<body>
<form>
  <label>Name:</label>
  <input type="text" name="name">
  <input type="Submit" name="submit" value="Submit">
</form>
  <script src="app.js"></script>
</body>
</html>

2 Answers

Dave Harker
PLUS
Dave Harker
Courses Plus Student 15,510 Points

Hi Patrick Shangala ,

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

/***
https://developer.mozilla.org/en-US/docs/Web/Events/submit 
Note that submit is fired only on the form element, not the button or submit input. (Forms are submitted, not buttons.)

So you'll need for change that addEventListener to listen on the 'form' not the 'submitButton'
You'll also need to listen for 'submit' not a 'click'
And lastly, to use the event (e) in your function, you'll need to pass it through 
***/  

submitButton.addEventListener('click', () => {
  e.preventDefualt();
});

I could write out the code but I hope that helps you more.
You're getting there! Keep up the effort :smile:

Happy coding,
Dave :dizzy:

patrick shangala
patrick shangala
6,217 Points

not all still can't figure it out ..can you please just show me the code or you also don't know

Dave Harker
Dave Harker
Courses Plus Student 15,510 Points
const form = document.querySelector('form');
const submitButton = form.querySelector('[type=Submit]');

form.addEventListener('submit', (e) => {
  e.preventDefault();
});

Good luck ... you're going to need it.