Is there any way to prevent a value from being selected in a dropdown? For example:
document.getElementById('teste').onchange = function (event){
var valor = this.value;
if(valor == 4){
alert('esse valor não pode!');
event.preventDefault();
return false;
}
}
<select id="teste">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
In the snippet above, if the value is 4, it should cancel the selection, and keep the value that was selected before. What is the right way to do this? Initially, I'm thinking of saving the value and selecting via javascript
if I can not select a certain value.
I accept solutions with or without jquery