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 trialpatrick shangala
6,217 Pointscan't understand the question someone to help me out with this problem
how can i solve this problem ?
const form = document.querySelector('form');
const submitButton = form.querySelector('[type=Submit]');
submitButton.addEventListener('click', () => {
e.preventDefualt();
});
<!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
Courses Plus Student 15,510 PointsHi 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
Happy coding,
Dave
patrick shangala
6,217 Pointsnot all still can't figure it out ..can you please just show me the code or you also don't know
Dave Harker
Courses Plus Student 15,510 Pointsconst form = document.querySelector('form');
const submitButton = form.querySelector('[type=Submit]');
form.addEventListener('submit', (e) => {
e.preventDefault();
});
Good luck ... you're going to need it.