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

General Discussion

Best way to handle changes of <select> element

On my main page (index.html) I have a list of some objects which have a category field for example. And on top of page I have element selecting category. So, what is best way to handle it like this: when changes selected category in - change a list of objects (view only objects with selected category). Can I make it using only Java+Spring+Thymeleaf or I have to use JavaScrypt or other tool also?

2 Answers

I think it is better to use JavaScript. Checkout this Stack Discussion:

http://stackoverflow.com/questions/10570904/use-jquery-to-change-a-second-select-list-based-on-the-first-select-list-option

It is a bit different: they are trying to change the second select, based on option selected in first select. But I think it is still a way I would go, when I get to Recipe Site. Jquery is a solution I think, because after all exactly for things like this we use JavaScript: to add interactivity on one page.

I think you have to use JavaScript/jQuery and AJAX. You could use document.getElementById('id').value to check the current value and then do something with it using AJAX