I am trying to set attribute required
for html options in jquery and here are what I tried from reading online and none of them works:
$("#transaction_payee_id")[0].setAttribute("required", "true");
$("#transaction_payee_id")[0].setAttribute("required", true);
$("#transaction_payee_id").prop("required", true);
$("#transaction_payee_id").attr("required", true);
The first option in html is empty which is required for setup required
. Here is the html source code. The value for required
is empty:
<select id="transaction_payee_id" name="transaction[payee_id]" class="select required form-control" required="">
<option value=""></option>
<option value="1">option2</option>
<option value="2">option2</option>
</select>
The command is not complicated. What's missing in the code?