Retrieve data from a text file stored locally, store it in an array, and populate a <select> dropdown with the

Greetings! I am working on an application in htaEdit where I require to read a text file line by line and insert each line into a select dropdown. Here is the code for the select dropdown:

   <select  onchange="disableCategory();" style="width:220px;margin-left:80px;"  id="dropdown2" name="">
       <option value="" selected="default" disabled>Select...</option>
   </select>

I am uncertain how to write JavaScript to achieve this. However, I have successfully tested uploading a local file and processed it using ActiveX with the following code:

      var fso = new ActiveXObject("Scripting.FileSystemObject"); 
      var s = fso.OpenTextFile("sample.txt", 1, true);
      var row = s.ReadLine();  
      alert(row);

My text file contains about 10 words like: AA BB CC .. and so on.

Answer №1

let fileSystem = new ActiveXObject("Scripting.FileSystemObject"); 
let file = fileSystem.OpenTextFile("test.txt", 1, true);
selection = document.getElementById('dropdown2');
let array=new Array();
let index=0;
do {
array[index]=file.readLine();
}
while(file.readLine!=null);
for (index = 0; index<array.length; index++){
    let option = document.createElement('option');
    option.value = "option"+(index+1);
    option.innerHTML = array[index];
    selection.appendChild(option);
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The z-index overlapping problem in webkit browsers is a result of Angular 7 animations

I have implemented staggered animations in my Angular 7 application to bring elements to life upon page load. However, I am facing a strange z-index problem with one of my components. Here is the animation code: @Component({ selector: 'track-page& ...

Attach the Bootstrap-Vue modal to the application's template

I am implementing a custom modal using bootstrap-vue modal in my project on codesandbox. This is the template structure: <template> <b-button variant="link" class="btn-remove" @click="removeItemFromOrder(index)"> Remove item </b-bu ...

The method to disable the dropdown for a select tag in a Polymer Dom-module is not functioning properly

I need help modifying the country dropdown based on a value retrieved from backend code If the disabled_value is 0, I want to hide the dropdown and make it unselectable If the disabled_value is 1, I want to enable the dropdown for selecting countries &l ...

Attempting to develop a straightforward JavaScript presentation display

The slideshow will cycle through six images named 1.jpg, 2.jpg, 3.jpg, 4.jpg, 5.jpg, and 6.jpg var showarray = ["1.jpg","2.jpg","3.jpg","4.jpg","5.jpg","6.jpg"]; var i = 0; for( i = 0; i < 6; i++) { // Is there a way to pause the script for two ...

Attempting to employ the HTML5 file picker feature within the AppMaker platform

Hey there, I'm currently working on integrating the HTML5 file picker into my AppMaker app. (Since my app needs to run as the developer, I can't use Drive Picker). I've been able to display the file picker in an HTML widget using the follow ...

Unable to view new content as window does not scroll when content fills it up

As I work on developing a roulette system program (more to deter me from betting than to actually bet!), I've encountered an issue with the main window '#results' not scrolling when filled with results. The scroll should always follow the la ...

Push function is not available in Redux

Currently, I am facing an issue while trying to use the state of a component in other components. Since this state needs to be accessed by multiple components, I have decided to switch to Redux. However, I encountered an error 'newUsers.push is not a ...

Restangular failing to apply headers during post requests

I have been encountering an issue while trying to set the header for a single post request using Restangular. Despite following the documentation here and seeking help from a similar question, the request is being sent as plain text instead of JSON. My se ...

Testing a Svelte Component with Unit Tests { #conditionals }

Test Procedure Instructions To begin, execute the following bash command: mkdir example && cd example && mkdir src && touch jest.config.js && pnpm init && pnpm i @jest/globals @testing-library/svelte jest jest-envi ...

The page refreshes when the anchor element is clicked

Currently, I am working on enhancing a web application that is built on the foundation of traditional aspx (asp.net) web forms with elements of Angular 6 incorporated into it. My current assignment involves resolving a bug that triggers a page refresh whe ...

Exploring the Functionality of worker-loader Inline

It was my understanding that the Webpack worker-loader configuration below: ... module: { rules: [ { test: /worker\.js/, loader: "worker-loader", options: { inline: 'fallba ...

There was an error during module build process: ReferenceError occurred due to an unrecognized plugin "import" specified in "base" at position 0

I have encountered an error while working on my ReactJS project using create-react-app. The error arose after I added and removed a package called "react-rte". Now, every time I try to start my project, I get the following error: Error in ./src/index.js Mo ...

What is the most efficient way to condense multiple repetitive case statements?

Within my code, I have multiple case statements that are quite similar, with the only difference being the argument 'key' from the function click(key). The variable 'c' is represented as JSON. The challenge lies in incorporating the ar ...

What are alternative methods to prevent a div from expanding in width from the right side other than using position absolute?

Looking to create a div element that only expands from the left side as content is added? <div id="sent_message" style='background-color: #2b89cc; color: white; font-family: Arial,Helvetica, sans-serif; margin-top: 10px; display: ...

Click on the link in the modal to either download the image or view a larger version

Struggling to create a photo gallery similar to Google Photos because of large image sizes - around 15mb - causing slow loading for users with poor connections. Currently using a placeholder image while waiting for the full-size image to load, but encount ...

Can I use leaflet to customize the types of roads displayed on the map?

Is there a way to customize the types of roads displayed at different zoom levels using data from the OSM highways list? I have checked the Leaflet documentation but couldn't find the answer. If you happen to come across it, please share the link. e ...

I am experiencing issues with the functionality of front-page.php on my WordPress website

Seeking guidance in addressing a web development issue: I have encountered a problem with a website that I am currently working on locally using WordPress. I added the following code to the header.php file: <link rel="stylesheet" type="text/css" href= ...

Tips for resizing a Numpy array using zero padding

I am facing a challenge with reshaping a Numpy array. The current array looks like: array([1, 2, 3, 4, 5, 6, 7, 8]) My goal is to reshape it into an array that resembles: array([[5, 0, 0, 6], [0, 1, 2, 0], [0, 3, 4, 0], [7, 0, 0, 8] ...

Employing the Map function in React leads to an error that is undefined

Upon simplifying my code, it seems that I am encountering an unresolved issue with the map function being used in different locations. I have noticed that code from examples running on platforms like Codepen does not work in my locally created react app p ...

Tips for successfully accessing a variable in an Angular Pipe

When displaying output, I need to show a specific number of decimal digits based on the length returned by a stored procedure. The length of these decimal digits can vary, and I only need to focus on the decimal part, not the integer part. To achieve this, ...