[Sign-up] Javascript can parse the form and combine it into a JSON object

#3
This commit is contained in:
eoghan.conlon 2023-08-01 13:45:08 +01:00
parent ff6b3b6056
commit f1e819bab9

View file

@ -7,18 +7,32 @@
</head> </head>
<body> <body>
<h1>Sign-up</h1> <h1>Sign-up</h1>
<form id="form"> <form id="register">
<label for="auth">Auth code</label> <label for="auth">Auth code</label>
<input type="text" id="auth" name="auth" /> <br/> <input type="text" id="auth" name="auth" /> <br/>
<label for="uid">Username</label> <label for="user">Username</label>
<input type="text" id="uid" name="username" /> <br /> <input type="text" id="user" name="user" /> <br />
<label for="pass">Password</label> <label for="pass">Password</label>
<input type="password" id="pass" name="password" /> <input type="password" id="pass" name="pass" />
<input type="Submit" value="Submit"/> <input type="Submit" value="Submit"/>
</form> </form>
<footer> <footer>
UL Computer Society 2023-<span id="year">2023</span> UL Computer Society 2023-<span id="year">2023</span>
</footer> </footer>
<script>
const formEl = document.getElementById("register");
formEl.addEventListener('submit', (listener) => formHandler(listener));
function formHandler(listener){
listener.preventDefault();
const formData = new FormData(formEl);
const auth = formData.get("auth");
const user = formData.get("user");
const pass = formData.get("pass");
const object = { auth: auth, user: user, pass: pass }
alert(JSON.stringify(object));
}
</script>
</body> </body>
<script> <script>
document.getElementById('year').textContent = new Date().getFullYear().toString() document.getElementById('year').textContent = new Date().getFullYear().toString()