title: Storing the clicked value in radio buttonswith cookies
body: <p>Hey guys am new to js actually..I have two radio buttons and a save button..The code i have done</p>
  
  <pre><code>    &lt;input id="male" type="radio" name="sex" id="male" value="male"&gt;Male
  &lt;input id="female" type="radio" name="sex" id="female" value="female"&gt;Female
  &lt;button id="buttons"&gt;Save me &lt;/button&gt;
  
  &lt;script&gt;
  
  function setCookie(cname,cvalue,exdays) {
  var d = new Date();
  d.setTime(d.getTime() + (exdays*24*60*60*1000));
  var expires = "expires=" + d.toGMTString();
  document.cookie = cname+"="+cvalue+"; "+expires;
  }
  
  
  var c = document.getElementById('buttons');
  c.onclick = function() {
  var c = document.getElementById('male');
  var m = document.getElementById('female');
  
  if(c.checked == 'true') {
  setCookie('samplecookie', c.value, 30 );
  } else if(n.checked == 'true') {
  setCookie('anothersamplecookie', n.value, 30);
  }
  
  }
  &lt;/script&gt;
  </code></pre>
  
  <h1>What should i need to do.</h1>
  
  <p>Suppose i clicked on the female radio button and click the save button the value needs to be stored and the value will remain be checked even the page is refreshed..The above code didnt works for me ..The radio  button gets unchecked when the page is refreshed..</p>
  
  <p>I have asked a similar qus <a href="https://stackoverflow.com/questions/27924961/keep-the-selected-option-saved-within-js/27926172#27926172">here</a>.But it didnt helped me ..I have heard this can be done with localstorage too..But i dont reall know how to.</p>
  
  <p>Hope you guys  would help me with the right code and will be really appreciated..</p>