I build an example, how to read and parse data from dat file, and assigning it into text fields:
1.dat file structure
3
"Caroline Martin","2007 E.L Road","Los Angeles CA 87457",43
"Brian Green", "210 AB Street","New York NY 10002",52
"Amy Baker","3213 Canta Mount", "Miami FL 33133",61
HTML
<form>
<input id="txtName1" type='text'/>
<input id="txtAdd11" type='text'/>
<input id="txtAdd21" type='text'/>
<input id="txtAge1" type='text'/>
<input id="txtName2" type='text'/>
<input id="txtAdd12" type='text'/>
<input id="txtAdd22" type='text'/>
<input id="txtAge2" type='text'/>
<input id="txtName3" type='text'/>
<input id="txtAdd13" type='text'/>
<input id="txtAdd23" type='text'/>
<input id="txtAge3" type='text'/>
</form>
Javascript
var client = new XMLHttpRequest();
client.open('GET', '1.dat');
client.onload = (function(){
var txt = client.responseText;
var arr = [];
var lines = txt.split('\n');
for(j=1; j < lines.length; j++)
{
lines[j] = lines[j].replace(/["]/g,'');
arr[j] = lines[j].split(",");
document.getElementById('txtName'+j).value = arr[j][0];
document.getElementById('txtAdd1'+j).value = arr[j][1];
document.getElementById('txtAdd2'+j).value = arr[j][2];
document.getElementById('txtAge'+j).value = arr[j][3];
}
})
client.send(null);
Whole code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>Template</title>
</head>
<body>
<form>
<input id="txtName1" type='text'/>
<input id="txtAdd11" type='text'/>
<input id="txtAdd21" type='text'/>
<input id="txtAge1" type='text'/>
<input id="txtName2" type='text'/>
<input id="txtAdd12" type='text'/>
<input id="txtAdd22" type='text'/>
<input id="txtAge2" type='text'/>
<input id="txtName3" type='text'/>
<input id="txtAdd13" type='text'/>
<input id="txtAdd23" type='text'/>
<input id="txtAge3" type='text'/>
</form>
<SCRIPT TYPE="text/javascript">
var client = new XMLHttpRequest();
client.open('GET', '1.dat');
client.onload = (function(){
var txt = client.responseText;
var arr = [];
var lines = txt.split('\n');
for(j=1; j < lines.length; j++)
{
lines[j] = lines[j].replace(/"/g,'');
console.log(lines);
arr[j] = lines[j].split(",");
document.getElementById('txtName'+j).value = arr[j][0];
document.getElementById('txtAdd1'+j).value = arr[j][1];
document.getElementById('txtAdd2'+j).value = arr[j][2];
document.getElementById('txtAge'+j).value = arr[j][3];
}
})
client.send(null);
</SCRIPT>
</body>
</html>