I’m working with Express.js, MongoDB and Mongoose, EJS and I’m having a heard time with selecting an option from the data in the database.
<div class="mb-3 col-md-3">
<label
for="stage"
class="form-label text-muted"
>Stage</label
>
<select
class="form-select"
name="deal[stage]"
aria-label="Default select example">
<option selected>Choose One</option>
<option value="lead">Lead</option>
<option value="inquiry">Inquiry</option>
<option value="qualified">Qualified</option>
<option value="demo">Demo</option>
<option value="negotiation">Negotiation</option>
<option value="closure">Closure</option>
</select>
</div>
I can do something like this using ejs and that is fine with a few options, but I’m sure that there is a better way.
<div class="mb-3 col-md-3">
<label
for="hot"
class="form-label text-muted"
>Hot</label
>
<select
id="hot"
class="form-select"
value="<% deal.hot %>"
aria-label="Default select example">
<option selected>Choose One</option>
<% if(deal.hot === 'true') { %>
<option
value="true"
selected>
True
</option>
<option value="false">False</option>
<% } else { %>
<option value="true">True</option>
<option
value="false"
selected>
False
</option>
<% } %>
</select>
</div>