How to save user input and refresh page using Javascript? -


i writing function in js that's form in table (1 row, 3 columns). first cell input box, second 2 buttons. want once user enters text (say country), , clicks "submit", want save value entered in variable, once clicks "refresh", page refreshed country in mind. how write functions saves value , refreshes page? here's code have (some of code answer):

function createtable(){      var body = document.body, tbl  = document.createelement('table');     tbl.style.width='100%';     tbl.style.border = "0px solid black";     tbl.style.backgroundcolor = "green";     tbl.setattribute("style", "font-size:18px;position:absolute;top:0px;right:00px;");      for(var = 0; < 1; i++){         var tr = tbl.insertrow();         for(var j = 0; j < 3; j++){                 if (j == 2) {                     var td = tr.insertcell();                     input=document.createelement("input");                     input.type="option";                     input.value="enter country";                     td.appendchild(input)                  } else if (j == 1) {                     var td = tr.insertcell();                     btn=document.createelement("button");                     btn.setattribute("type", "button")                      var t=document.createtextnode("submit");                      btn.appendchild(t);                     td.appendchild(btn);                  } else if (j == 0) {                  var td = tr.insertcell();                 var btn=document.createelement("button");                 var t=document.createtextnode("refresh");                 btn.appendchild(t);                 td.appendchild(btn)                          }         }     }      body.appendchild(tbl); }   createtable(); 

use localstorage:

check if value exists:

if(localstorage.getitem("country"))     // value exists else     // value not exist 

set new value

localstorage.setitem("country", insert_name_here); 

get old value:

localstorage.getitem("country"); 

Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -