<div id="use-same-address-selection-container" class="input-field">
<label for="delivery-same">Use Same Address?</label>
<div class="picker">
<span class="radio-wrap">
<input type="radio" name="delivery-same" id="delivery-same-yes" value="yes" class="same-address-picker"><label for="delivery-same-yes">YES</label>
</span>
<span class="radio-wrap">
<input type="radio" name="delivery-same" id="delivery-same-no" value="no" class="same-address-picker"><label for="delivery-same-no">NO</label>
</span>
</div>
</div>
I know there are similar questions here, but I've looked through tons of answers and articles and have not found a solution or explanation for my situation yet.
I am attempting to set the 'checked' attribute of a type=radio input in this way:
$("#use-different-address").prop('checked', true);
Then, in the line immediately underneath, I print out an alert to see the value of the 'checked' attribute, and am continuously getting back 'undefined.'
alert("Value of the checked property for use-different-address = " + $("#use-different-address").prop('checked'));
I've been moving it all around the document to try it in different places in the execution flow, tried putting it in a $(document).ready(), rolling it into other custom functions, using alternative syntax (e.g., attr instead of prop), but nothing has allowed me to set this to 'checked' automatically when the page loads.
Oddly enough, when I click one of the options manually, the box gets checked and acts normal from then on (I can change the selection, functions trigger off of the changes normally, etc.) until I refresh or return to the page, after which neither option is checked and the values for 'checked' are 'undefined' again.
Note: I'm not trying to simply set a 'checked' default, so doing something like putting 'checked=true' in the HTML for the input will not work; it is supposed to be set based on whether or not a sessionStorage variable is set (I can set and successfully read this value, so that's not the issue), so I need to be able to change the value of the'checked' property after that sessionStorage variable is detected.