It's about the browser stage.
<script type="text/javascript">
function fnPickedFlow(){
return #('input[name=pickedFlow]:checked').val();
}
$( document ).ready(function() {
console.log( "pickedFlow:" + fnPickedFlow() );
// The first time return "one"
// The second time return "two"
});
</script>
<input type="radio" name="pickedFlow" value="one" checked/>
<input type="radio" name="pickedFlow" value="two" />
The first time when page loads, Radio button one
is selected by default. When changing the selection to two
and submitting, the redirection happens. And user click browser back button (javascript:history.back()
) to come back to this page, pickedFlow
is pointing to one
but the selected button in UI is two
.
Change code add autocomplete off
for each of radio button to avoid the situation:
<script type="text/javascript">
function fnPickedFlow(){
return #('input[name=pickedFlow]:checked').val();
}
$( document ).ready(function() {
console.log( "pickedFlow:" + fnPickedFlow() );
// Always return "one"
});
</script>
<input type="radio" name="pickedFlow" value="one" autocomplete="off" checked/>
<input type="radio" name="pickedFlow" value="two" autocomplete="off" />
Also see:
https://forum.vuejs.org/t/radio-button-retains-old-state-on-browser-back-button/97417