How do I add an index to my localstorage using only HTML, CSS and JavaScript? -
this html page used add student
<!doctype html> <head> <link href="style.css" rel="stylesheet" type="text/css"> <script src="function.js"></script> </head> <header> <nav> <img src="logo.jpg"><h1 id="titt">north park clubs</h1> <li><a href="attendance.html">attendance</a></li> </nav> </header> <body> <h1>add student</h1> <input type="text" id="indx"></input> <input type="text" id="sfirstname"></input> <input type="text" id="slastname"></input> <input type="text" id="snumber"></input> <input type="text" id="spoints"></input> <input type="button" onclick="save()" value="save"></input> </body>
this html page view attendance
<!doctype html> <head> <link href="style.css" rel="stylesheet" type="text/css"> <script href="functions.js"></script> </head> <header> <nav> <img src="logo.jpg"><h1 id="titt">north park clubs</h1> <li><a href="attendance.html">attendance</a></li> </nav> </header> <body onload="load()"> <table id="attendance"> <input type="button" value="add student" id="add" link="addstudent.html"> <tr> <td></td> <td>first name</td> <td>last name</td> <td>student number</td> <td>points</td> <td>absent (if student present leave unchecked)</td> </tr> <td id="indx"></td> <td id="sfirstname"></td> <td id="slastname"></td> <td id="snumber"></td> <td id="spoints"></td> <td><input id="a" type="checkbox"></td> </table> </body>
this javascript
var indx = []; var sfirstname = []; var slastname = []; var snumber = []; var spoints = []; var = []; var attendance = []; var obj = json.parse(attendance); function save(){ localstorage.setitem("idex", document.getelementbyid('indx').value); localstorage.setitem("fname", document.getelementbyid('sfirstname').value); localstorage.setitem("lname", document.getelementbyid('slastname').value); localstorage.setitem("numb", document.getelementbyid('snumber').value); } if (localstorage.clickcount) { localstorage.clickcount = number(localstorage.clickcount) + 1; } else { localstorage.clickcount = 1; } document.getelementbyid("result").innerhtml = "you have clicked button " + localstorage.clickcount + " time(s)."; //var fname = localstorage.sfirstname; //var lname = localstorage.slastname //var numb = localstorage,snumber //onload document.getelementbyid('attendance'); function load(){ document.getelementbyid.idex; document.getelementbyid.fname; document.getelementbyid.lname; document.getelementbyid.numb; }
i'm not quite sure doing wrong explanation great! thanks! :)
the question how add index localstorage using html, css , javascript?
coding wise html5 , css have nothing except displaying end values.
here's fiddle: http://jsfiddle.net/f3aej450/2/
javascript(onload):
//check see if index exists. // set 0 if not, // otherwise add 1 (localstorage.getitem("index")) ? localstorage.setitem("index", parseint(localstorage.getitem('index')) + 1) : localstorage.setitem("index", 0); // alert user index number alert(localstorage.getitem("index"));
as side note, suggest using sessionstorage
opposed localstorage
- difference sessionstorage clears when browser window/tab closed. localstorage sits there until overwrite or remove it.
Comments
Post a Comment