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 trialhum4n01d
25,493 PointsGetting a error with e.target.elements on form submission
I’m trying to implement Guil’s onSubmit handler but I’m getting a Uncaught TypeError: Cannot read property '0' of undefined
in reference to e.target.elements
. It appears that the elements array does not exist… Any help would be appreciated Guil Hernandez
2 Answers
Adriaan Janse van Rensburg
2,708 PointsIt is hard to figure out what is going on without seeing your code, but here is my handleSubmit function in the Home.js file.
handleSubmit(event){
event.preventDefault();
let teacherName = event.target.elements[0].value;
let teacherTopic = event.target.elements[1].value;
let path = `featured/${teacherTopic}/${teacherName}`;
browserHistory.push(path);
}
Hopefully the finished function can help you out :)
Alexander Mackenzie
10,542 PointsThe ` made the difference for mine as I was using ' at first!
hum4n01d
25,493 PointsYeah I think that was also my issue; I didn’t realize that template strings needed a backtick instead of a normal quote :)
hum4n01d
25,493 Pointshum4n01d
25,493 PointsThanks, that worked
hum4n01d
25,493 Pointshum4n01d
25,493 PointsIt actually turned out that I misspelled
elements
aseements
somehow!Adriaan Janse van Rensburg
2,708 PointsAdriaan Janse van Rensburg
2,708 PointsGlad I could help.