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 React Router Basics Going Further with Routes Navigating Routes Programmatically

Getting 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 undefinedin 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
Adriaan Janse van Rensburg
2,708 Points

It 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 :)

Thanks, that worked

It actually turned out that I misspelled elements as eements somehow!

The ` made the difference for mine as I was using ' at first!

Yeah I think that was also my issue; I didn’t realize that template strings needed a backtick instead of a normal quote :)