jakbo
10-08-2005, 08:22 PM
I'm not sure exactly how to do this. I have a file called datafile.js. I have another file called Objects.js. I have another file called sales.html to bring it alll together.
Here is datafile.js, which I created to test my other stuff:
//datafile.js
var datafile = new Array();
datafile.push("Smith,Mary:9/9/2001:sw:5000:24000");
datafile.push("Wilen, Bill:4/18/1994:ne:4000:26000");
datafile.push("Wang, Chon:7/1/1998:ne:6000:30000");
datafile.push("Normal, Abi:1/21/2000:nw:10000:25000");
datafile.push("Arnold, Sarah:10/16/1990:sw:2000:27000");
datafile.push("Lowe, Sam:1/13/1992:sw:2000:24500");
datafile.push("Brody, Louise:1/26/1998:ne:3000:28000");
datafile.push("Chee, James:4/15/2004:sw:3200:25000");
datafile.push("Webb, Jack:11/4/2002:nw:6500:32500");
datafile.push("Mann, Beth:11/4/2006:nw:6500:32500");
datafile.push(":11/4/2002:nw:6500:32500");
datafile.push("Nabo, Ned:8/4/2003:nw:7100:-30900");
datafile.push("Inderfurth, Apo:2/4/2000:xw:3100:9900");
Here is Objects.js, which I'm using for all of my functions and to sort through the data:
//Objects.js
function verify(Employee){
alert("Just added "+Employee.name+".");
}
function Employee(name, dateOfHire, division, sales, salary){
this.name=name;
this.dateOfHire=dateOfHire;
this.division=division;
this.sales=sales;
this.salary=salary;
this.show=showAll;
verify(this);
this.empNo=++Employee.key;
}
Employee.key=0;
function showAll(){
document.writeln(this.name+"<br>");
document.writeln(this.dateOfHire+"<br>");
document.writeln(this.division+"<br>");
document.writeln(this.sales+"<br>");
document.writeln(this.salary+"<br>");
}
var workers=new Array();
function stepThru(){
for(i=0;i<datafile.length;i++){
workers[i]=new Array();
workersAttr=datafile[i].split(':');
for (j=0;j<workersAttr.length;j++){
workers[i][j]=workersAttr[j];
}
}
}
And this is what I'm using to bring it all together:
//sales.html
<html>
<head>
<style type = "text/css">
table{font-family: verdana,arial,sans-serif;
font-size: .7em;}
</style>
<script src = "datafile.js" type = "text/javascript"></script>
<script src = "Objects.js" type = "text/javascript"></script>
<script type = "text/javascript">
</script>
</head>
<body onload="stepThru();">
<table>
</table>
</body>
</html>
I can recreate the results from stepThru() manually to instantiate a new Employee, but I can't figure out how to do it automatically each time a new datafile is added to datafile.js.
This is what I did when I was trying to see if my object would work in the first place:
var workers = new Array();
workers[workers.length] = new Employee("Smith, Mary","9/9/2001","sw",5000,24000);
Would somebody explain to me how to instantiate the Employee object straight from the stepThru function?
Here is datafile.js, which I created to test my other stuff:
//datafile.js
var datafile = new Array();
datafile.push("Smith,Mary:9/9/2001:sw:5000:24000");
datafile.push("Wilen, Bill:4/18/1994:ne:4000:26000");
datafile.push("Wang, Chon:7/1/1998:ne:6000:30000");
datafile.push("Normal, Abi:1/21/2000:nw:10000:25000");
datafile.push("Arnold, Sarah:10/16/1990:sw:2000:27000");
datafile.push("Lowe, Sam:1/13/1992:sw:2000:24500");
datafile.push("Brody, Louise:1/26/1998:ne:3000:28000");
datafile.push("Chee, James:4/15/2004:sw:3200:25000");
datafile.push("Webb, Jack:11/4/2002:nw:6500:32500");
datafile.push("Mann, Beth:11/4/2006:nw:6500:32500");
datafile.push(":11/4/2002:nw:6500:32500");
datafile.push("Nabo, Ned:8/4/2003:nw:7100:-30900");
datafile.push("Inderfurth, Apo:2/4/2000:xw:3100:9900");
Here is Objects.js, which I'm using for all of my functions and to sort through the data:
//Objects.js
function verify(Employee){
alert("Just added "+Employee.name+".");
}
function Employee(name, dateOfHire, division, sales, salary){
this.name=name;
this.dateOfHire=dateOfHire;
this.division=division;
this.sales=sales;
this.salary=salary;
this.show=showAll;
verify(this);
this.empNo=++Employee.key;
}
Employee.key=0;
function showAll(){
document.writeln(this.name+"<br>");
document.writeln(this.dateOfHire+"<br>");
document.writeln(this.division+"<br>");
document.writeln(this.sales+"<br>");
document.writeln(this.salary+"<br>");
}
var workers=new Array();
function stepThru(){
for(i=0;i<datafile.length;i++){
workers[i]=new Array();
workersAttr=datafile[i].split(':');
for (j=0;j<workersAttr.length;j++){
workers[i][j]=workersAttr[j];
}
}
}
And this is what I'm using to bring it all together:
//sales.html
<html>
<head>
<style type = "text/css">
table{font-family: verdana,arial,sans-serif;
font-size: .7em;}
</style>
<script src = "datafile.js" type = "text/javascript"></script>
<script src = "Objects.js" type = "text/javascript"></script>
<script type = "text/javascript">
</script>
</head>
<body onload="stepThru();">
<table>
</table>
</body>
</html>
I can recreate the results from stepThru() manually to instantiate a new Employee, but I can't figure out how to do it automatically each time a new datafile is added to datafile.js.
This is what I did when I was trying to see if my object would work in the first place:
var workers = new Array();
workers[workers.length] = new Employee("Smith, Mary","9/9/2001","sw",5000,24000);
Would somebody explain to me how to instantiate the Employee object straight from the stepThru function?