/*
JavaScript Unleashed, Third Edition
by Richard Wagner and R. Allen Wyke
ISBN: 067231763X
Publisher Sams CopyRight 2000
*/
<html>
<head>
<title>Intranet Employee Database</title>
<script type="text/javascript">
<!--
// Global variables
var i = 0;
// Create Array objects
var empList = new Array();
// Employee object constructor
function employee(FirstName, LastName, HomePhone, Ext, EmailAddress) {
this.FirstName = FirstName;
this.LastName = LastName;
this.HomePhone = HomePhone;
this.Ext = Ext;
this.EmailAddress = EmailAddress;
this.show = show;
}
function show() {
alert(this.FirstName + "/n" +
this.LastName + "/n" +
this.HomePhone + "/n" +
this.Ext + "/n" + this.EmailAddress);
}
function addEmployeeObject(FirstName, LastName, HomePhone, Ext,
EmailAddress) {
empList[i] = new employee(FirstName, LastName, HomePhone, Ext,
EmailAddress);
}
function insertRecord() {
FirstName = document.form1.FirstName.value;
LastName = document.form1.LastName.value;
HomePhone = document.form1.HomePhone.value;
Ext = document.form1.Ext.value;
EmailAddress = document.form1.EmailAddress.value;
i++;
addEmployeeObject(FirstName, LastName, HomePhone, Ext, EmailAddress);
}
function showAll() {
objWindow = window.open("", "", "width=600,height=300");
objWindow.document.write("<html><body>");
objWindow.document.write("<h1>Object Description</h1>");
objWindow.document.write("<p>");
for (var q=1; q<empList.length; q++) {
objWindow.document.write("<strong>" + empList[q].FirstName
+ " " + empList[q].LastName + "</strong></p>");
objWindow.document.write("<p>" + empList[q].HomePhone + "</p>");
objWindow.document.write("<p>" + empList[q].Ext + "</p>");
objWindow.document.write("<p>" + empList[q].EmailAddress + "</p>");
objWindow.document.write("</body></html>");
}
objWindow.document.close()
}
//-->
</script></head>
<body>
<h1>Dyanamic Object Creator</h1>
<p>Enter employee information in the form below and click the Add button.
Press the Show All button to view a list of all employees you have
entered.</p>
<form name="form1">
<pre>
First Name:
<input type=text size=20 maxlength=256 name="FirstName">
</pre>
<pre>
Last Name:
<input type=text size=20 maxlength=256 name="LastName">
</pre>
<pre>
Home Phone:
<input type=text size=20 maxlength=256 name="HomePhone">
</pre>
<pre>
Ext.:
<input type=text size=20 maxlength=256 name="Ext">
</pre>
<pre>
Email Address:
<input type=text size=20 maxlength=256 name="EmailAddress">
</pre>
<pre>
<input type="button" name="Add" value="Add" onClick="insertRecord()">
<input type="button" name="ShowAll" value="Show All"
onClick="showAll()">
</pre>
</form>
</body>
</html>
|