I have an array of data that I want to compare to the input in a text field. If the input matches an element in the array, I want to display a checkmark, and if it doesn't match, I want to display a crossmark.
However, I'm having an issue where it either displays a checkmark for all numbers entered or a crossmark. Here is my JavaScript code:
**
> var data={"number":{"1234","7742","3452","6543","0091"}};
function validation(){
var numbersearch =document.getElementById("validate").value;
for(var i=0; i<data.number.length; i++) {
if( data.number[i] === numberInput) {
document.querySelector('.checkmark').style.display = "block"; }
else if(numberInput === '') {
document.querySelector('.checkmark').style.display = "none"; }
else{
document.querySelector('.crossmark').style.display = "block"; } } }
**
HTML:
<div>
<input id="validate" type="text" maxlength=4 placeholder="0000">
<svg class="checkmark>
<scg class="crossmark>
</div>
Can someone help me figure out what I'm doing wrong here? I've connected the validation() function to the HTML using an angular component. My goal is to display the class .checkmark when there is a match and .crossmark when there is not a match.