Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- *** Page 1
- <!-- Kevin Niland -->
- <!-- Web Storage using JSON -->
- <!DOCTYPE html>
- <html>
- <head>
- <title>Web Storage using JSON 1</title>
- </head>
- <body>
- <a href = "Web Storage using JSON 2.html">Link 1</a>
- <script>
- function cars(type, model, color)
- {
- this.type = type;
- this.model = model;
- this.color = color;
- }
- var carOne = new cars("Honda", "Civic", "White");
- var carTwo = new cars("Fiat", "Uno", "Red");
- var carThree = new cars("Toyota", "RAV4", "Green");
- var carFour = new cars("Nissan", "Tarrano", "Blue");
- var carArray = [carOne, carTwo, carThree, carFour];
- localStorage.item1 = JSON.stringify(carArray);
- </script>
- </body>
- </html>
- *** Page 2
- <!-- Kevin Niland -->
- <!-- Web Storage using JSON -->
- <!DOCTYPE html>
- <html>
- <head>
- <title>Web Storage using JSON 2</title>
- </head>
- <body>
- <a href = "Web Storage using JSON.html">Link 2</a>
- <!-- <p>
- <button onclick = "carOne()" type = "button">Car 1</button>
- <button onclick = "carTwo()" type = "button">Car 2</button>
- <button onclick = "carThree()" type = "button">Car 3</button>
- <button onclick = "carFour()" type = "button">Car 4</button>
- </p> -->
- <!-- <button onclick = "displayArray()" type = "button">Display Array</button> -->
- <br>
- Car Manufacturer: <input type = "text" name = "manufacturer"><br>
- Car Model: <input type = "text" name = "model"><br>
- Car Color: <input type = "text" name = "color"><br>
- <p><button onclick = "carOne()" type = "button">Save to local storage</button></p>
- <p id = "car_1"></p>
- <p id = "car_2"></p>
- <p id = "car_3"></p>
- <p id = "car_4"></p>
- <!-- <script>
- function carOne()
- {
- var car1R = JSON.parse(localStorage.item1);
- document.getElementById("car_1").innerHTML = car1R.type;
- document.getElementById("car_2").innerHTML = car1R.model;
- document.getElementById("car_3").innerHTML = car1R.color;
- }
- function carTwo()
- {
- var car2R = JSON.parse(localStorage.item2);
- document.getElementById("car_1").innerHTML = car2R.type;
- document.getElementById("car_2").innerHTML = car2R.model;
- document.getElementById("car_3").innerHTML = car2R.color;
- }
- function carThree()
- {
- var car3R = JSON.parse(localStorage.item3);
- document.getElementById("car_1").innerHTML = car3R.type;
- document.getElementById("car_2").innerHTML = car3R.model;
- document.getElementById("car_3").innerHTML = car3R.color;
- }
- function carFour()
- {
- var car4R = JSON.parse(localStorage.item4);
- document.getElementById("car_1").innerHTML = car4R.type;
- document.getElementById("car_2").innerHTML = car4R.model;
- document.getElementById("car_3").innerHTML = car4R.color;
- }
- </script> -->
- <!-- <script>
- function displayArray()
- {
- var cars_Array = JSON.parse(localStorage.item1);
- document.getElementById("car_1").innerHTML = cars_Array[0].type;
- }
- </script> -->
- <script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement