My if condition is returning a value even when it clearly goes against the condition specified. Here is my code:
<html>
<div id="page-wrapper">
<div>
Select a text file:
<input type="file" id="fileInput">
</div>
<pre id="fileDisplayArea"><pre>
</div>
<p id="csvData"></p>
<button onClick="test()">Search text document</button>
<script>
function test (){
var file = fileInput.files[0];
var textType = /text.*/;
var csvType = 'application/vnd.ms-excel';
if (file.type.match(csvType)) {
var reader = new FileReader();
reader.onload = function(e) {
var array =reader.result.split(",");
var look = prompt ('Enter your GTIN-8 code')
if (look=(array [0]))
{
document.getElementById("csvData").innerHTML=(array [1]);
}
else
{
document.getElementById("csvData").innerHTML=("GTIN-8 code not found");
}
}
reader.readAsText(file);
} else {
fileDisplayArea.innerText = "File not supported";
}
I want it to be able to return "GTIN-8 code not found" when the value entered into the prompt is not the same as the first value in the array and to return the second value in the array when it is. Currently it just returns the second value even if nothing is entered into the prompt box. Thanks any help would be appreciated.
Aucun commentaire:
Enregistrer un commentaire