[Sign-up] Javascript can parse the form and combine it into a JSON object
#3
This commit is contained in:
parent
ff6b3b6056
commit
f1e819bab9
1 changed files with 18 additions and 4 deletions
|
@ -7,18 +7,32 @@
|
|||
</head>
|
||||
<body>
|
||||
<h1>Sign-up</h1>
|
||||
<form id="form">
|
||||
<form id="register">
|
||||
<label for="auth">Auth code</label>
|
||||
<input type="text" id="auth" name="auth" /> <br/>
|
||||
<label for="uid">Username</label>
|
||||
<input type="text" id="uid" name="username" /> <br />
|
||||
<label for="user">Username</label>
|
||||
<input type="text" id="user" name="user" /> <br />
|
||||
<label for="pass">Password</label>
|
||||
<input type="password" id="pass" name="password" />
|
||||
<input type="password" id="pass" name="pass" />
|
||||
<input type="Submit" value="Submit"/>
|
||||
</form>
|
||||
<footer>
|
||||
UL Computer Society 2023-<span id="year">2023</span>
|
||||
</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>
|
||||
<script>
|
||||
document.getElementById('year').textContent = new Date().getFullYear().toString()
|
||||
|
|
Loading…
Reference in a new issue