changing search to use for loop rather than jquery each