I'm a bit of a beginner, but I have a code webpage that makes a post request to my server and replies with a JSON encoded array of associated arrays.
Next I use a text input field and on .keyup the code works with the array as a sort of search feature.
$( function() {
$('#questionSearchInput').keyup(function(){
var list = [];
search = $(this).val().toString();
searchArray = search.split(" ");
console.log(searchArray);
$.each(grabbedItems, function(j, question){
question.score = 0;
console.log(question.score);
});
if(searchArray[0]){
$.each(grabbedItems, function(i, question){
lowerName = question.name.toLowerCase();
if(lowerName.indexOf(searchArray[0]) > -1){
question.score = question.score + 1;
console.log(question.score);
}
});
}
It runs the if(searchArray[1]) section a few times for each element in the search array and then dynamically loads onto the page.
grabbedItems.sort(function(a, b){
return b.score - a.score;
});
if(grabbedItems.length < 1){
document.getElementById("noQuestionsP").style.display = "block";
}
clearBox("questionNamesDisplay");
$.each(grabbedItems, function(k, question){
if(k < 5){
var place = document.getElementById("questionNamesDisplay");
var item = document.createElement("a");
item.innerHTML = question.name;
item.href = question.link;
item.style.display = "block";
place.appendChild(item);
}
});
});
});
What I mean is that .keyup doesn't work on Iphones as the input element must be dealt with differently.
Does anyone with more knowledge than me know of a better solution or way of fixing this?