0

I have a basic input field that i want to convert to a drop down. In order to control inputs I want to define the choices. Is there a way to pull the contents of a text or CSV file and use them to populate the choices for a dropdown? I have been search but so far i havent found anything. I am reading the input value into a javascript variable that is doing calculations.

Any suggestions would be appreciated.

matt_739
  • 11
  • 1

2 Answers2

0

To read the file from the web server, you need a back-end (server-side) language, such as PHP or asp.NET.

By far the most common is PHP, as it's the "P" in XAMPP, LAMP, WAMP, MAMP, etc. Most of the shared hosting packages available from big hosting companies like GoDaddy, NameCheap, HostGator, etc are LAMP stacks (Linux, Apache, MySQP, PHP). If PHP is installed on your server, all you must do to use it is name the file using extension .php instead of .html. In fact, you don't need .html again -- every file can be named .php and it will work exactly the same as a file that ends .html -- except that, if required, it can now process PHP code.

To use PHP on your own computer, install XAMPP (available for OSX, Windows and Linux). Note that the web folder is c:\xampp\htdocs and you "see" the web page by type (only) localhost into the browser address bar.

Here is a series of (free) tutorial videos about PHP.

If you wish to keep polling the file to see if there are changes, you can use AJAX. See this post for information about AJAX and how it works.

Community
  • 1
  • 1
cssyphus
  • 37,875
  • 18
  • 96
  • 111
0

You can achieve this without the need of a back-end language. Here is a pastebin example using jQuery and an Ajax request to get the data from a CSV file. I am assuming you have a webserver that enables you to serve CSV files from an URL (e.g. http://yourwebsite.com/csv/your_data.csv).

Ressources (just in case):

christophetd
  • 3,834
  • 20
  • 33