I want to dynamically create a <select></select> (or maybe a textbox with autocomplete) input file depending on an Excel file with a format like this:
Airport Code Airport Name Language Code
AAC Al Arish en
AAE Annaba Les Saline en
AAH Aachen Merzbruck en
AAL Aalborg en
AAN Al Ain en
AAQ Anapa en
AAR Aarhus Tirstrup en
AAU Asau en
(with many more)
I would need to open the .xls file and read every row so that I can get the two first colums to act as the anchor and value.
This is the most related content I’ve found and the links are broken How to read and write into file using JavaScript
Is there a solution for this that will work for IE7
If your file is on the http server you can read it using AJAX.
Let’s first define some constants:
CSV_URL is the URL of your CSV file.
CSV_COLUMN is delimiter character which devides columns.
CSV_ROW is delimiter character which devides rows.
Now we need to do AJAX query to get the CSV data content.
I’m using jQuery to do AJAX requests.
Ok, now we need to parse the data…
… and create the select:
Everything besides AJAX request is pure JavaScript. If you don’t want jQuery for some reason, you can write your AJAX request in pure JS as well.