jquery plugin and autocomplete

More
3 years 2 months ago #112634 by EducatedPredictions
EducatedPredictions created the topic: jquery plugin and autocomplete
I am trying to use a csv to autocomplete a question in one of my surveys. I believe I followed the instructions right in the manual.

Here is what i came up with for my php:
<?php
 
        $collegesArr = array();
 
        $file_handle = fopen("colleges.csv", "r");
 
        while (!feof($file_handle) ) {
                $line_of_text = fgetcsv($file_handle);
                array_push($collegesArr, $line_of_text[0]);
        }
 
        fclose($file_handle);
 
        echo json_encode($collegesArr);
 
?>
And here is what I came up with for my js source:
<script type="text/javascript" charset="utf-8">
 
        $(document).ready(function() {
 
                var qID = 111;
                var url = "templates/sherpa/colleges.php";
                var dataArr = [];
 
                $.getJSON(url,function(data){
 
                        $.each(data,function(i, item){
                                dataArr.push(item);
                        });
 
                        $('#question'+qID+' input.text').autocomplete({
                                source: dataArr
                        });
 
                });
 
        });
 
</script>

In terms of the jquery ui plugin - are there additional steps that I am not taking that is preventing this from working? I have tried the full url of the php file with no luck. Thanks for any help anyone can offer.

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now
Join our Newsletter!