moamen
moamen

Reputation: 191

File input onchange function is not fired when I select a file

I have the following html element:

<input type="file" id="file-selector",onchange="readJson(this)" accept=".txt, .json, "> </input>

and the following function:

function readJson(selector) {
    console.log("I'm a sucessful onchange event!")
    var fileList = selector.files;
    loadJsonAsText(fileList[0]);
    
}

When I choose a file and open the console I don't see "I'm a sucessful onchange event!", indicating that the function didn't work, how can I fix that?

Upvotes: 1

Views: 54

Answers (1)

Marco somefox
Marco somefox

Reputation: 368

Add a space between id and onchange

<input type="file" id="file-selector" onchange="readJson(this)" accept=".txt, .json, "> </input>

Upvotes: 1

Related Questions