Jul-12-2020, 12:32 PM
Hello Coders,
I'm still working on my project for the course, and I'm not giving up, even if everything looks to slow me down!
I'm at the point where I'm building the page edit_recipe.html to edit an existing recipe. Honestly I could do everything, I'm just wasting a lot of time on the select tag. I want to take the value category.name from MongoDB, to use an if to see if they match, and in that case <option> takes the value selected, otherwise not. How can achieve this? Please let me know if you want me to explain more, I hope the code (that is completely wrong) it already explains my purpose well. Thank you!!!
I'm still working on my project for the course, and I'm not giving up, even if everything looks to slow me down!
I'm at the point where I'm building the page edit_recipe.html to edit an existing recipe. Honestly I could do everything, I'm just wasting a lot of time on the select tag. I want to take the value category.name from MongoDB, to use an if to see if they match, and in that case <option> takes the value selected, otherwise not. How can achieve this? Please let me know if you want me to explain more, I hope the code (that is completely wrong) it already explains my purpose well. Thank you!!!
<select id="category" name="category_name"> <option value="pasta">Pasta</option> <option value="meatfish" {% if recipe.category_name == 'meatfish': "selected" %}>Meat&Fish</option>{%endif%} <option value="vegetarian">Vegetarian</option> <option value="dessert">Dessert</option> <option value="baking">Baking</option> </select>