Sunday 7 March 2021

Getting checked value after using back button

I have the following code on a web page:

<script>
jQuery(function(){ 
    console.log($("[name='type']:checked").val());
})
</script>

<form>
A <input type="radio" name="type" value="A"> &nbsp;&nbsp;
B <input type="radio" name="type" value="B"><br>
<input type="submit" name="submit" value="submit">
</form>

When I load the page, the output in the console is, naturally, 'undefined'. Let's say I select the 'A' option, click the submit button and then click the browser's back button. The 'A' option is still checked but the console output is also still 'undefined'. That doesn't seem right. Obviously I want the output to be 'A'. What am I doing wrong?



from Getting checked value after using back button

No comments:

Post a Comment