Sm00rf9000 Sm00rf9000 - 2 months ago 11
Javascript Question

Get text value from .txt file

I have a script which gets a value from a .txt file, I have done it with a number value where it works perfectly, but when I want to do it with another .txt file, which is a text and not a number I get the "NaN" error which I know stands for "not a number", but then how do I change it to work so that I can get the value text in the .txt file?

My script.

<div class="displayNameCurrent">
Display name: <span id="displayNameDisplay"></span>
</div>

<script type="text/javascript">
var read = new XMLHttpRequest();
read.open('GET', 'displayNameFile.txt', false);
read.send();

var displayName = parseInt(read.responseText)
document.getElementById("displayNameDisplay").innerHTML = displayName;
</script>

Answer

If you don't want to convert the text to an integer, simply don't run parseInt over it.