read file using ActiveX separate by ; and put in select - option

3.3k views Asked by At

My goal: i need to read txt file using fso - activeX then separate text by ; and put each separated word in select - option. so far i got this but aint working

<script>
    function readAll() {
        var fso = new AcitveXObject("Scripting.FileSystemObject");
        var txtFile = fso.OpenTextFile("kategorije.txt", 1, false, 0);
        var fText = txtFile.ReadAll();
        txtFile.Close();
    }

    var array = fText.split(";");
    var sel = document.getElementById("dropdown2");
    for (var i = 0; i < dropdown2.length; i++) {
        var opt = document.createElement("option");
        opt.innerHTML = fText[i];
        opt.value = fText[i];
        sel.appendChild[opt];
    }
</script>
1

There are 1 answers

0
user2599279 On
function readAll() {
    var fso = new ActiveXObject("Scripting.FileSystemObject");
    var txtFile = fso.OpenTextFile("kategorije.txt", 1, false, 0);

    var fText = txtFile.ReadAll();
    txtFile.Close();
    fso = null
    var array = fText.split("\r\n");
    var sel = document.getElementById("dropdown2");
    for (var i = 0; i < array.length; i++) {
        var opt = document.createElement("option");
        opt.innerHTML = array[i];
        opt.value = array[i];
        sel.appendChild(opt);
    }
}

my code works now and it look like this