You need to either assign a
name
or an
id
to your input elements so you can select them and read the values. For example:
<input type="text" name="username">
<input type="password" id="password">
const username = document.getElementsByName("username")[0].value;
const password = document.getElementById("password").value
Alternatively, provided you give your inputs valid names, you can use the
FormData
object and provide the parent form. Simply wrap the input elements in a form, give it an
id
and:
<form id="some-form"> .. </form>
const form = document.getElementById("some-form");
const data = new FormData(form)