I would like that when I select the select "reject",
that an input field opens immediately and if I select something else
select something else, this input field is closed again.
<div class="col-md-12 mb-12 mt-3">
<label for="order_status">status:</label>
<select class="form-select form-select" name="order_status" id="order_status">
<option value="">select</option>
<option value="accepted">accepted</option>
<option value="reject" id="rejectID">reject</option>
</select>
</div>
<div id="showDiv" style="display: none">
<input type="text" name="reject_commit">
</div>
<script>
$(function () {
$("select[name='order_status']").click(function () {
if ($("#rejectID").is("reject")) {
$("#showDiv").show();
} else {
$("#showDiv").hide();
}
});
});
</script>
2
Answers
If you have id attribute use a id selector, then checks select’s (this keyword) value. Dont use click but change handler:
You can do it like this, check the value of your select id, not just the id of the reject option