I’m having a problem where I want to get all elements in an array at once with one line of code. The problem is, I’m using .push
to add extra elements. I want to select all existing and input elements by user. Here is an example.
let pass = [
"example",
"wow"
];
var message3 = document.getElementById("signup");
document.getElementById("myButton3").addEventListener("click", function() {
pass.push(message3.value);
alert(pass)
});
var message4 = document.getElementById('password');
document.getElementById("myButton4").addEventListener("click", function() {
if (message4.value == pass) { // Here.
alert('you pass!')
}
else {
alert('wrong')
}
});
<input type="text" id="signup" value="">
<br>
<button id="myButton3" type="button">Create password</button>
<br>
<input type="text" id="password" value="">
<br>
<button id="myButton4" type="button">Enter password</button>