My object: Take latitude, longitude columns from textfile(.txt) and mark them on googlemap api v3.

For the first step, I made a code for reading textfile by javascript and html. When I run this code, chrome and IE browser open well but nothing happened. javascript part don't work. How can I fix it?

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<script type="text/javascript">
    var fso=new ActiveXObject("Scripting.FileSystemObject");
    var filename="C:\\text.txt";
    function savefile() {
        if (!fso.FileExists(filename)) {
            fso.CreateTextFile(filename,true);
        }
        var 
f=fso.OpenTextFile(filename,2,true);

f.Write(myarea.innerHTML);
        f.Close();
    }
    function loadfile() {

if (!fso.FileExists(filename)) {

fso.CreateTextFile(filename,true);

}
        var f=fso.OpenTextFile(filename,1);
        r=f.ReadAll();
        f.Close();
        myarea.innerHTML=r;
    }

function window.onload() {
        loadfile(filename);

}
</script>
<div id=myarea contenteditable=true 
style="width:320;height:240;border:solid 2 
inset;overflow:scroll;background-color:silver;"></div>
<br><input 
type=button value=load onclick=loadfile()><input type=button value=save 
onclick=savefile()>
</body>
</html>

text.txt => (delimiter = " ")

year class sex a b c d
1 1 f 90 80 60 100 
1 1 m 90 80 60 100 
1 2 f 90 70 60 100 
2 1 f 100 80 60 100 
3 1 m 90 99 60 100

Chrome won't work bcause you're using an ActiveXObject, that only works in IE (unless you've added a plug in).
Windows is failing because your syntax is incorrect. Your window.onload should look like this:

window.onload = function() {
        loadfile(filename);
}

In your loadfile function you ned to check for the end of the file while reading and define the r object:

function loadfile() {
   if (!fso.FileExists(filename)) {
      fso.CreateTextFile(filename,true);
   }
        var f=fso.OpenTextFile(filename,1);
        var r = null;
        while(!f.AtEndOfStream) {
            r=f.ReadAll();
        }
        f.Close();
        myarea.innerHTML=r;
    }

That still outputs 'null' onto the screen but that's all I have time for right now.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.