0

I am trying to use this tutorial to make an autocomplete recommendation populated by a list of files in a folder 'template'. How can I modify the JS code to show recommendations based on file names in the template folder instead of the listed generated in the sample code?

I am using this tutorial.

enter image description here

$(function(){
  var currencies = [
    { value: 'Afghan afghani', data: 'AFN' },
    { value: 'Albanian lek', data: 'ALL' },
    { value: 'Algerian dinar', data: 'DZD' },
    { value: 'European euro', data: 'EUR' },
    { value: 'Angolan kwanza', data: 'AOA' },
    { value: 'East Caribbean dollar', data: 'XCD' },
...
    { value: 'Vietnamese dong', data: 'VND' },
    { value: 'Yemeni rial', data: 'YER' },
    { value: 'Zambian kwacha', data: 'ZMK' },
    { value: 'Zimbabwean dollar', data: 'ZWD' },
  ];
k3llydev
  • 2,057
  • 2
  • 11
  • 21
  • 1
    To do this, you would need to either build the array manually (hard code the contents of your template folder into your code, which doesn't work well if the contents of that folder is changing), or you would have to do it on the back end. If this is plain html/javascript/jquery, without being written in a server-side language like PHP, Python, Ruby, etc, then you can't do it without hard-coding it, because javascript can not see the contents of the server's file system. But if you have a back end language, you can have it read the contents of the folder and write the array into the page... – Reverend Pete May 01 '19 at 23:00
  • ahhhh i see, i appreciate the response. – user2875004 May 02 '19 at 01:58
  • @ReverendPete actually, JavaScript can do see the contents of server's file system. It's called Node.js... But the main idea of this is that you need a back-end language to read the server's file system data. – k3llydev May 02 '19 at 03:48
  • Let's read https://stackoverflow.com/questions/48636376/get-filenames-in-a-given-directory-using-jquery – sylvain May 02 '19 at 05:08

0 Answers0