I am creating a form with two text boxes: Task and Description. What I want to do is be able to console.log in both boxes and save the input through a submit button.
i.e:
task: do laundry
Description: do a buttload of laundry(idk lol)
Alright, I got that down(I think). But what I want to do after is that once I backspace and clear it, I want to add another task and description, but I also want to add that AFTER the saved input.
ie: task: do laundry, study Description, do a buttload of laundry, study a lot
Can someone check my code and see what's wrong? It's just showing the console.log input, which is nice, but I want to be able to use the push method to add to the end of my arrays and SAVE it.
function submitForm() {
var FormData = {
task: myForm.task.value,
description: myForm.description.value
};
myJSON = JSON.stringify(FormData);
localStorage.setItem("formJSON", myJSON);
text = localStorage.getItem("formJSON");
obj = JSON.parse(text);
console.log(FormData);
return false;
};
newArray = [task, description];
var taskArray = [];
var descriptionArray = [];
var task = document.getElementById("task").value;
var description = document.getElementById("description").value;
function addTask(task) {
taskArray.push(task);
console.log(" " + taskArray.join(", "));
}
function addTask(task) {
taskArray.push(task);
console.log(" " + taskArray.join(", "));
}
function addDescription(description) {
descriptionArray.push(task);
console.log(" " + descriptionArray.join(", "));
}
<!DOCTYPE html>
<html>
<title>Task Form</title>
<body>
<form class="form-inline" name="myForm" onsubmit=" return submitForm()">
<label class="required">*Task and Description* </label>
<!first text box>
<div class="form-group">
<input type="text" id="task" placeholder="Task">
</div>
<!second comment box>
<div class="form-group">
<input type="text" id="description" placeholder="Description">
</div>
<button type="submit" class="btn btn-default submit">Submit</button>
</form>
<script type="text/javascript " src="json.js "></script>
</div>
</p>
</form>
</body>
</html>
All tasks and description has to be in array form and packaged in JSON.