Trying to set Radio button in Update form
when user clicks update/edit button, a new window opens and loads the previous values that user entered in the respective elements with the radio buttons checked/set to the previous values but no radio buttons are selected
It is multiple choice question type with 6 options and user selects 1 out of them trying to set with name (as ID's are unique to all the radio buttons in the group) but not solved
enter code here
//this code works in console:
$('#inlineRadio1_1').attr('checked', true);
// but the below code does not when trying to set/check radio button
var SetRadio1; //previous radio button value in the variable SetRadio1 from 1 to 6
if (SetRadio1 == 1) {
$('#inlineRadio1_1').attr('checked', true);
}
else if (SetRadio1 == 2) {
$('#inlineRadio1_2').attr('checked', true);
}
else if (SetRadio1 == 6) {
$('#inlineRadio1_6').attr('checked', true);
}
<div class="col-md-12 pb-4">
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="inlineRadioOptions1" id="inlineRadio1_1" value="1">
<label class="form-check-label" for="inlineRadio">1</label>
</div>
<div class="form-check form-check-inline px-1">
<input class="form-check-input" type="radio" name="inlineRadioOptions1" id="inlineRadio1_2" value="2">
<label class="form-check-label" for="inlineRadio">2</label>
</div>
<div class="form-check form-check-inline px-1">
<input class="form-check-input" type="radio" name="inlineRadioOptions1" id="inlineRadio1_3" value="3">
<label class="form-check-label" for="inlineRadio">3</label>
</div>
<div class="form-check form-check-inline px-1">
<input class="form-check-input" type="radio" name="inlineRadioOptions1" id="inlineRadio1_4" value="4">
<label class="form-check-label" for="inlineRadio">4</label>
</div>
<div class="form-check form-check-inline px-1">
<input class="form-check-input" type="radio" name="inlineRadioOptions1" id="inlineRadio1_5" value="5">
<label class="form-check-label" for="inlineRadio">5</label>
</div>
<div class="form-check form-check-inline px-1">
<input class="form-check-input" type="radio" name="inlineRadioOptions1" id="inlineRadio1_6" value="6">
<label class="form-check-label" for="inlineRadio">6</label>
</div>
</div>
```````````````````````````````````
$.ajax({
url: _spPageContextInfo.webAbsoluteUrl + "/_api/Web/Lists/GetByTitle('SharePointList')/items?$filter=ID eq " + ID_number,
type: "GET",
async:false,
headers: {
"accept": "application/json;odata=verbose",
},
success: function (data) {
$("#Cars").val(data.d.results[0]["Car"]); //text area, works
$("#Books").val(data.d.results[0]["Book"]); //text area, works
$('input[name=inlineRadioOptions1][value=' + data.d.results[0]["Score_x0020_Q1"] + ']').prop('checked','checked'); //does not work
$('input:radio[name="inlineRadioOptions1"]').attr('checked', true); //does not work
$('#inlineRadio1_1').attr('checked', true); //by ID, works when tried in console
},
error: function (error) {
alert(JSON.stringify(error));
}
});