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

dylan kane
dylan kane
2,772 Points

How 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?

u can do this in html directly

<button  onclick = "function()">Submit</button>
Carlos José
Carlos José
Courses Plus Student 12,431 Points

You 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
Kevin Korte
28,149 Points

I'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
dylan kane
2,772 Points

Yes I am working with mean stack

1 Answer

Kevin Korte
Kevin Korte
28,149 Points

Wouldn'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
dylan kane
2,772 Points

No 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