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.

dylan kane
2,772 PointsHow to link javascript events to html buttons
I need to have a javascript event linked to an html button where when it is clicked it adds a value to a mongo database. Any tips and what I should do?

Carlos José
Courses Plus Student 12,431 PointsYou need a Back-End language if anything. Because the info has to be sent to the server that will in turn do things in a database.

Kevin Korte
28,109 PointsI'm assuming the backend language here would be node.js Carlos José based on him mentioning mongo. My guess is he's working in the MEAN stack.

dylan kane
2,772 PointsYes I am working with mean stack
1 Answer

Kevin Korte
28,109 PointsWouldn't that button just be a "submit" button for a form, and than at that point, you're just doing a standard ajax form submit with js.
Even if you didn't want or need any user fields, the form could have hidden fields that still submit.

dylan kane
2,772 PointsNo it is not a standard submit button, it is adding a specific string to the database, like if you pressed the button it would put a word into a document on mongodb
Suresh Raina
Courses Plus Student 205 PointsSuresh Raina
Courses Plus Student 205 Pointsu can do this in html directly
<button onclick = "function()">Submit</button>