Skip to content

Commit 7511a07

Browse files
JS file for Form Section (#376)
* Create Github-Pages Created Github Page Blog. Please check it and review it. * formscript
1 parent 9574d1d commit 7511a07

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

formScript.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
function storeData(e) {
2+
e.preventDefault(); // prevent default form submission
3+
4+
const formData = new FormData(form);
5+
const userData = {};
6+
7+
// iterate over the form fields and store their values in the userData object
8+
formData.forEach((value, key) => {
9+
userData[key] = value;
10+
});
11+
12+
// store the userData object in localStorage
13+
localStorage.setItem("userData", JSON.stringify(userData));
14+
}
15+
const storedData = localStorage.getItem("userData");
16+
const userData = JSON.parse(storedData);
17+
18+
console.log(userData);

0 commit comments

Comments
 (0)