I have this function:
function accentFold(inStr) {
return inStr.replace(/([àáâãäå])|([ç])|([èéêë])|([ìíîï])|([ñ])|([òóôõöø])|([ß])|([ùúûü])|([ÿ])|([æ])/g,
function(str,a,c,e,i,n,o,s,u,y,ae) {
if(a) return 'a';
else if(c) return 'c';
else if(e) return 'e';
else if(i) return 'i';
else if(n) return 'n';
else if(o) return 'o';
else if(s) return 's';
else if(u) return 'u';
else if(y) return 'y';
else if(ae) return 'ae';
});
}
function checkResults(searchString) {
jQuery('.swiper-slide').each(function() {
var currentElement = $(this);
var valorname = currentElement.find("p").html();
var valornamelatin = accentFold(valorname);
var searchResult = valorname.match(searchString, "i");
var searchResultLatin = valornamelatin.match(searchString, "i");
if (searchResult != null || searchResultLatin != null){
currentElement.show();
countResults ++;
} else {
currentElement.hide();
}
swiperCatego01.reInit();
});
alert ("One Alert");
}
$(document).ready(function() {
$('#friendsSearch').keyup(function(){
var searchString = $(this).val();
var countResults = "0";
checkResults(searchString);
alert(countResults);
if (countResults == 0) {
$('#nohayCoincidencias').fadeIn();
} else {
$('#nohayCoincidencias').hide();
swiperCatego01.reInit();
}
});
})
What this function does is it searches on a list of people for the matching names through an input text box. The function works properly hiding the names that don't contain the searched criteria, but the odd thing is that I can get anything done after the .each() function, I'm not that good with jQuery and I'm wondering if there's something I'm doing wrong, I can't make the alert to work or anything else whatsoever.
Example in:
http://design.rankon.me/appdesign/invitetemplate.php
Edit:
It's actually working on Google Chrome but fails to work on Safari of iPhone which is my final destination, so the solution must work on Safari on ios6 +
You have declared countResults inside a keyup function, so its only declared inside that scope. So it throws error when you try to do
countResults ++;
You should declare the variable as global one above all functions:
var countResults = "0";