Hmm, after a little exploring, it turns out that there is a "select" event that gets fired when an autocomplete selection is made. This means that you don't need the listener. You can use that event to populate your ID and Email questions.
So, assuming all questions are on the same page, the script would look something like The following.
Replace:
- "NN" with the "Name" question ID
- "II" with the "ID" question ID
- "EE" with the "Email" question ID
Modify the path to your CSV file.
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
var qNameID = NN;
var qIDID = II;
var qEmailID = EE;
var url = "upload/templates/yourTemplate/yourCsvFile.csv";
// Create an array to hold the names
var namesArr = new Array();
// Grab the CSV contents
$.get(url,function(data){
// Convert CSV contents to an array of arrays
fullArray = jQuery.csv()(data);
// Load the names array
$(fullArray).each(function(i, item){
namesArr.push(item[0]);
});
// Initialise the autocomplete plugin
$('#question'+qNameID+' input.text').autocomplete({
source: namesArr,
// Event fired when a selection is made (ui.item.value refers to the selected item)
select: function(event, ui) {
// Find the "ID" and "Email" values associated with the selected name value and load those questions
$(fullArray).each(function(i, item){
if(item[0] == ui.item.value) {
$('#question'+qIDID+' input.text').val(item[1]);
$('#question'+qEmailID+' input.text').val(item[2]);
}
});
}
});
});
});
</script>