I would like to implement a select input feature where users can choose from predefined options, with the added functionality of including a text input field as the last option for users who prefer to enter their own category. How can I achieve this?
Currently, my HTML code includes:
<div class="form-group">
<label for="postCategory">Category</label>
<select class="form-control" name="category">
<option name="table1" value="1" selected="true" disabled="disabled">Select A Category</option>
<option name="category1" value="general">General</option>
<option name="category2" value="tech">Tech</option>
</select>
</div>
In the backend, user input is captured using the following code after form submission:
app.post('/compose', function(req, res) {
console.log(req.body.category);
});
How can I incorporate a text input field within the last option of the select menu, allowing users to input their own category if they do not wish to choose 'General' or 'Tech'? How can I retrieve this data in the backend?