Python Forum
form select option tags, add "selected" on <option> in python at a condition
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
form select option tags, add "selected" on <option> in python at a condition
#1
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!!!

        <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>
Reply


Messages In This Thread
form select option tags, add "selected" on <option> in python at a condition - by Leon79 - Jul-12-2020, 12:32 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  a Python class for Option deberi 5 2,908 Apr-28-2020, 08:05 AM
Last Post: buran
  #python .... Need to develop a if condition from two lists ginu 2 2,900 Oct-05-2018, 12:45 PM
Last Post: gruntfutuk
  Questions about the GET and POST submission form Functions in Python for a Trivia Gam martin28 8 4,179 Aug-05-2018, 09:47 PM
Last Post: snippsat
  click menu option 6 it does not print out what I need it to AMRiley23 4 3,992 Nov-27-2017, 09:03 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020