Reputation: 784
I an having a scenario in my site that user has the option to select one from the yes or no through radio buttons provided. In this I have a persistance logic that holds the ID for the input radio button and the value that has checked.
on reloading the page I have to put the radio button to checked which he has selected. I am using :
document.getElementById($scope.preservedData.userData[i].id).click();
where UserData[i].id
holds the ID for the radio button.
<div class="radios col-xs-6">
<input type='radio' id="yesforques${resultsList.index}" name='question${resultsList.index}' ng-click="macinitialquestions($event,value,${resultsList.index})">
<label for="yesforques${resultsList.index}">
<span class="tkh-icons RadioBG"> </span>
<b> Yes </b>
</label>
</div>
<div class="radios no col-xs-6">
<input type='radio' id="noforques${resultsList.index}" name='question${resultsList.index}' ng-click="macinitialquestionsRevert(${resultsList.index})">
<label for="noforques${resultsList.index}">
<span class="tkh-icons RadioBG"> </span>
<b> No </b>
</label>
</div>
I have already tried the solutions provided like giving cursor : pointer
to the input but no luck. My click is not highlighting the radio button can someone help me in this?
Upvotes: 0
Views: 126
Reputation: 38
JS:
document.getElementById($scope.preservedData.userData[i].id).checked = true;
JQuery:
$($scope.preservedData.userData[i].id).prop("checked", true);
Upvotes: 1