I’m trying to disable an option from a selection through its value. When the value is equal to ‘sure’ the option is available. When the option is ‘wrong’ let it be disabled for options.
$(document).ready(function() {
$.getJSON("https://sheets.googleapis.com/v4/spreadsheets/1_TBtn730WbjJF_qRjo3c6SQXj_EeGU_qKOZbPTkVxfg/values/Page!A2:B5?key=AIzaSyArRlzwEZHF50y3SV-MO_vU_1KrOIfnMeI", function(result) {
$.each(result.values, function(i, field) {
$("#SelectTestID").append('<option hidden="hidden" selected="selected" value="">Options</option><option value="' + field[1] + '">' + field[0] + '</option>');
});
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.3/jquery.min.js"></script>
<select class="SelectTest" id="SelectTestID"></select>
>Solution :
If I’ve understood what you’re asking you can check the value of field[1] and set the disabled property of the option element accordingly.
Also note that in the example below I remove the hidden option element as it served no purpose, and I also used a template literal for building the string as it’s easier to read and less verbose.
$(document).ready(function() {
$.getJSON("https://sheets.googleapis.com/v4/spreadsheets/1_TBtn730WbjJF_qRjo3c6SQXj_EeGU_qKOZbPTkVxfg/values/Page!A2:B5?key=AIzaSyArRlzwEZHF50y3SV-MO_vU_1KrOIfnMeI", function(result) {
$.each(result.values, function(i, field) {
$("#SelectTestID").append(`<option value="${field[1]}" ${(field[1] === 'wrong' ? 'disabled' : '')}>${field[0]}</option>`);
});
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.3/jquery.min.js"></script>
<select class="SelectTest" id="SelectTestID"></select>