How to retain radio input state on page refresh

i have a form on which i need to store the state of all radio buttons if a user submit the form with errors (which in case the page would refresh).

I want to achieve something quite similar to this:

$(function(){ $('.example input[type="radio"]:checked').each(function(){ $(this).attr("checked",true); });

Any help would much be appreciated!


You could store it's state within local storage and restore it after each page load.

Little example on storing the value:

$('#myCheckbox').click(function () { localStorage['my.checkbox'] = this.checked; });

Restore it:

$('#myCheckbox').prop('checked', localStorage['my.checkbox'] == 'true');


Maybe you store the information in the session token or in a session cookie. If you use html5 components, you might try to use html local storage.


you just need to update the code

$(function(){ $('.example input[type="radio"]').each(function(){ $(this).attr("checked",$(this).checked()); });

It will save the property of radio button as user has selected for the radio button.


  • How to get or calculate size of Azure File/Share or Service
  • Where to save the local DB created for iphone app?
  • get passwords from chrome
  • Does the Azure table storage API cache results?
  • EntLib Way to Bind “Null” Value to Parameter
  • jquery code not working without breakpoint
  • Error in installing package: fatal error: stdlib.h: no such file or directory
  • How to make R's read_csv2() recognise the text characters properly
  • SAVE attribute needed for Fortran variables when only the C_LOC address is returned to a C program?
  • Django model inheritance, filtering models
  • saving file generated by TCPDF
  • how to avoid repetitive constructor in children
  • ADO and msqli connections very slow
  • d3 v4 drag and drop with TypeScript
  • PHP buffered output depending on server setting?
  • Custom Tabgroup Appcelerator
  • Spark fat jar to run multiple versions on YARN
  • PHPUnit_Framework_TestCase class is not available. Fix… - Makegood , Eclipse
  • Java Scanner input dilemma. Automatically inputs without allowing user to type
  • Projection media query: browser support and workarounds?
  • Deselecting radio buttons while keeping the View Model in synch
  • Nant, Vault & Windows Integrated Authentication
  • Different response to non-authenticated users and AJAX calls
  • Is possible to count alias result on mysql
  • ActionScript 2 vs ActionScript 3 performance
  • what is the difference between the asp.net mvc application and asp.net web application
  • VB.net deserialize, JSON Conversion from type 'Dictionary(Of String,Object)' to type '
  • Matrix multiplication with MKL
  • json Serialization in asp
  • Benchmarking RAM performance - UWP and C#
  • How can I get HTML syntax highlighting in my editor for CakePHP?
  • How do I configure my settings file to work with unit tests?
  • IndexOutOfRangeException on multidimensional array despite using GetLength check
  • Are Kotlin's Float, Int etc optimised to built-in types in the JVM? [duplicate]
  • costura.fody for a dll that references another dll
  • Reading document lines to the user (python)
  • Binding checkboxes to object values in AngularJs
  • Net Present Value in Excel for Grouped Recurring CF
  • jQuery Masonry / Isotope and fluid images: Momentary overlap on window resize
  • How to load view controller without button in storyboard?