To step one further:
The problem with the disabled
attribute on the selected option element is that the container <select>
element will also treated as disabled, and this leads to this select element's value will not being posted to the server at all, and JavaScript new FormData()
constructor also omit it.
To solve this, change the disabled to readonly
. And add the hidden
attribute also, so the selected option will not appear in the dropdown menu. With setting it's value to "" (falsy), the input validator prevents form submitting with a validation report, even without JavaScript.
This solution also solves the problem of the FormData constructor and you will also be able to easily find that this input has an invalid value with the Constraint Validation API's selectElement.checkValidity()
method.
<form>
<select name="status" required>
<option value="" hidden readonly selected>I am a placeholder...</option>
<option value="Good">Good</option>
<option value="Bad">Bad</option>
</select>
<input type="submit" value="Submit">
</form>