I have an app which collects data from input fields and appends it to the table. Please see my code below. What am I doing wrong?
function save(){
var name= $("#name").val();
var email= $("#email").val();
var telephone= $("#tel").val();
var street= $("#street").val();
var city= $("#city").val();
var state= $("#state").val();
var zip= $("#zip").val();
var inputArray = [name, email, telephone, street, city, state, zip];
var dataToStore = JSON.stringify(inputArray);
var uniqueID = ID();
sessionStorage.setItem(uniqueID, dataToStore);
display();
};
function display(){
var myArraySerialized = sessionStorage.getItem(uniqueID);
var myArray = JSON.parse( myArraySerialized );
var restoredName = myArray[0];
var restoredEmail = myArray[1];
var restoredTel = myArray[2];
var restoredStreet = myArray[3];
var restoredCity = myArray[4];
var restoredState = myArray[5];
var restoredZip = myArray[6];
//append filled information from the form to the table and 2 buttons - Update and Remove
$("#listContent table").append( "<tr>"+
"<td>" + restoredName + "</td>"+
"<td>" + restoredEmail + "</td>"+
"<td>" + restoredTel + "</td>"+
"<td>" + restoredStreet + "</td>"+
"<td>" + restoredCity + "</td>"+
"<td>" + restoredState + "</td>"+
"<td>" + restoredZip + "</td>"+
"<td>" + "<button>Update</button>" + "</td>" +
"<td>" + "<button>Remove</button>" + "</td>" +
"</tr>");
}
var ID = function () {
return '_' + Math.random().toString(36).substr(2, 9);
};
Though console says that uniqueID is not defined, and I do not understand why. When I use any other variable - name, email, street etc. - it passed, uniqueID - no. What am I doing wrong? Thanks for help