javascript - Set/Get Cookie for Form Input -


i'm new setting/getting cookies , hope can provide clarity.

i've searched high , low, , have come across many examples of how set , cookie retrieve value of input. unfortunately, post code examples...not visual.

the example i've found can see how works here. still leaves me scratching head, i'm unsure how get value display in same field after page refreshed.

below code, brief explanation of i'm trying do. brevity i've shortened markup.

upon session timeout, if user has entered text number of form fields, chosen options select menu, or checked checkbox, clicking button continue session refresh page. once page refreshed, need populated fields remain so.

i know using document.write highly frowned upon. this, however, used in example link provided. unsuccessfully tried using document.getelementbyid, store value after page refreshes.

<form id="frmguestinfo">   <input id="firstname" name="firstname" type="text" value=""> </form>  <button id="taocontbtn">   continue </button> 

and script, not working

jquery('#taocontbtn').on('click', function () {     location.reload(); // reload page      // set cookie     function getcookie(name) {         var re = new regexp(name + "=([^;]+)");         var value = re.exec(document.cookie);         return (value != null) ? unescape(value[1]) : null;     }      document.write(getcookie("firstname")); // cookie      // display cookie value in text field     // if(firstname = getcookie("firstname")) document.frmguestinfo.firstname.value = firstname;     if(firstname = getcookie("firstname")) document.getelementbyid('firstname');  }); 


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -