I am working on saving data from a HTML form to localStorage.
Here is my code so far
HTML
<form onSubmit="newRecipe()">
Recipe Name:<br>
<input type="text" value="Recipe" name="Recipe"><br>
Ingredients:<br>
<input type="text" name="Ingredients" value="Ingredients"><br><br>
<input type="submit" value="Submit">
</form>
JavaScript
function newRecipe(){
var inputrecipe= document.getElementById("Recipe");
localStorage.setItem("Recipe", JSON.stringify(Recipe));
var inputingredients= document.getElementById("Ingredients");
localStorage.setItem("Ingredients", inputingredients.value, JSON.stringify(testObject));
}
document.getElementById("test").innerHTML = localStorage.getItem("Recipe");
What am I doing wrong? when I submit the form I get a white screen and no localStorage save
newRecipe()function return false to prevent it from trying to POST to a blank page.return false;as the last statement in the function...