This snippet of code is designed for implementation into an AJAX Chat system to facilitate tab auto-completion of user names:
var usernames = new Array();
usernames[0] = "Saladin";
usernames[1] = "Jyllaby";
usernames[2] = "CadaverKindler";
usernames[3] = "qbsuperstar03";
var text = "Text and something else q";
// Initiating the script for integration
var searchTerm = text.slice(text.lastIndexOf(" ") + 1);
var i;
for(i = 0; i < usernames.length && usernames[i].substr(0,searchTerm.length) != searchTerm; i++);
// Script integration completes here
document.write(usernames[i]);
A few key points to note: The array of usernames and the text variable will be retrieved from the chat interface via AJAX (although I'm not currently familiar with that process), and the final output will also be managed through AJAX.
Are there more streamlined methods to achieve this functionality?
Additionally, any suggestions on how to handle multiple instances where the searchTerm is detected?