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 trialdylan 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,149 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,149 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>