简体   繁体   中英

Read txt file from local put into array and array into <select>

Hi im making some application in htaEdit. I need to take some txt file read each line of it and put each line in . Here's the code of select:

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

i have no idea how to make javascript for that. However i tested uploading file from local and managed in that using ActiveX using this code:

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

My txt file contain like 10 words AA BB CC .. smt like that

var fso = new ActiveXObject("Scripting.FileSystemObject"); 
var s = fso.OpenTextFile("test.txt", 1, true);
select = document.getElementById('dropdown2');
var arr=new Array();
var i=0;
do {
arr[i]=s.readLine();
}
while(s.readLine!=null);
for (i = 0; i<arr.length; i++){
    var opt = document.createElement('option');
    opt.value = "option"+(i+1);
    opt.innerHTML = arr[i];
    select.appendChild(opt);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM