This is a complete noob question for which I apologize in advance. I have a form that creates multiple instances of a contact text box that I want to use the same Autocomplete function. The ids on the fields are dynamic. The code as I have it works but rather than creating a function for each field, it would surely be better to create one function that handles the field ids with variables.
My script code in the header looks like this... $().ready(function() { $("#contacts1").autocomplete('getContacts.cfm', { minChars: 2, // The absolute chars we want is at least 1 character. delay:100, width: 600, // The width of the auto complete display max: 25, formatItem: function(row){ return row[0]; // Formatting of the autocomplete dropdown. } }); $("#contacts1").result( function(event, data, formatted) { // Make sure there's data if (data) $('#cpid1').val(data[1]); }); $("#contacts2").autocomplete('getContacts.cfm', { minChars: 2, // The absolute chars we want is at least 1 character. delay:100, width: 600, // The width of the auto complete display max: 25, formatItem: function(row){ return row[0]; // Formatting of the autocomplete dropdown. } }); $("#contacts2").result( function(event, data, formatted) { // Make sure there's data if (data) $('#cpid2').val(data[1]); }); }); Now the fields down in the form... <input name="EnvContactID_1" type="hidden" id="cpid1" /> <input type="text" name="EnvContactName_1" id="contacts1" size="65" /> <input name="EnvContactID_2" type="hidden" id="cpid2" /> <input type="text" name="EnvContactName_2" id="contacts2" size="65" /> Since the textbox fields are dynamic, these can grow very large in number. Thank you for the help and again, I'm sorry to ask such a beginner's question Jeff