Wednesday, April 11, 2012

Program JavaScript Record

<html>
<head><title >Membuat Rekaman Objek</title></head>
<body>
<script language = "JavaScript">
var Record = new Array();
function Mahasiswa(npm, nama, prodi, jenjang) {
// Properti
this.npm = npm;
this.nama = nama;
this.prodi = prodi;
this.jenjang = jenjang;
// Metode
this.LihatRecordMahasiswa = LihatRecordMahasiswa;
}
function LihatRecordMahasiswa() {
document.write("<td>" + this.npm + "</td>");
document.write("<td>" + this.nama + "</td>");
document.write("<td>" + this.prodi + "</td>");
document.write("<td>" + this.jenjang + "</td>");
}
//mengisi data
Record[0] = new Mahasiswa("43E001", "Dani", "TI", "S1");
Record[1] = new Mahasiswa("43E001", "Doni", "TI", "S1");
Record[2] = new Mahasiswa("43E001", "Dina", "TI", "S1");
Record[3] = new Mahasiswa("43E001", "Dini", "TI", "S1");
//menampilkan data
document.write("<table border = '1'>");
document.write("<th>NPM</th> <th>Nama</th>");
document.write("<th>Prodi</th><th>Jenjang</th> <br> ");
for (i=0; i < Record.length; i++)
{
document.write("<tr>");
Record[i].LihatRecordMahasiswa();
document.write("</tr>");
}
document.write("</table> <br>");
document.write("<table border = '1'>");
document.write("<th>NPM</th> <th>Nama</th>");
document.write("<th>Prodi</th><th>Jenjang</th> <br> ");
for (i=0; i < Record.length; i++)
{
document.write("<tr>");
Record[i].npm
document.write("</tr>");
}
document.write("</table>");
</script>
</body>
</html>

No comments:

Post a Comment