I have an array which contains words. Also i have a string. I need to check whether an element of array exists in a string. I've tried but without success. It's not working.
function inputValidate() {
var val = document.getElementById("title");
var keyWords = ["kerak", "nega", "qanday", "qanaqa", "nimaga", "mi"];
val.value.trim();
len = val.value.length - 1;
lastS = val.value.slice(len);
if (lastS != "?") {
document.getElementById("error").innerHTML = "Savol so`roq belgisi bilan tugashi lozim.";
} else {
document.getElementById("error").innerHTML = " ";
document.getElementById("error").style.color = "red";
}
for (i = 0; i < keyWords.length; i++) {
if (val.indexOf(keyWords[i]) != -1) {
document.getElementById("error2").innerHTML = "Gapingizga so`roq gapga o`xshamadi ";
} else {
document.getElementById("error2").innerHTML = " ";
}
}
}
i = 6instead ofi<keyWords.lengthis an errorvalwas a DOM node