Я создаю страницу form.html и пытаюсь получить массив с помощью Javascript в моем файле form.js с 5 полями, которые пользователь должен ввести с помощью querySelectorAll, но мой код не работает.
Что я делаю не так? Я хочу, чтобы мой JS-код находил все поля, которые:
- входные элементы
- начни с тхт
- либо type=txt, либо type=password
window.addEventListener('DOMContentLoaded', function() {
let divMain = document.getElementById("divMain");
let inputElements = divMain.getElementById("frmRegister").querySelectorAll(input[id ^= txt][type = "text"], input[id ^= txt][type = "password"]);
console.log(inputElements.length);
});
<h2 class="container">Form/jQuery</h2>
<div class="container" id="divMain">
<form action="form.html" method="get" name="frmRegister" id="frmRegister">
<table>
<tr>
<td>Login</td>
<td><input required type="text" name="field1" id="txtfield1" /> <span id="spnLogin"></span></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" id="txtPassword"> <span id="spnPasswordComplexity"></span></td>
</tr>
<tr>
<td>Confirm Password</td>
<td><input type="password" id="txtConfirmPassword"> <span id="spnPasswordCompare"></span></td>
</tr>
<tr>
<td>Email</td>
<td><input type="text" id="txtEmail"> <span id="spnEmail"></span></td>
</tr>
<tr>
<td>Confirm Email</td>
<td><input type="text" id="txtConfirmEmail"> <span id="spnEmailCompare"></span></td>
</tr>
<tr>
<td colspan="2"><input type="submit" id="btnRegister" value="Register"></td>
</tr>
</table>
</form>
</div>
querySelectorAll('input[id^="txt"][type="text"], input[id^="txt"][type="password"]')
- person Umair Khan   schedule 18.08.2020document.getElementById("frmRegister")
- person mplungjan   schedule 18.08.2020let inputElements = document.getElementById("frmRegister").querySelectorAll('input[id^=txt][type="text"], input[id^=txt][type="password"]');
- person mplungjan   schedule 18.08.2020