<?php
include "config/koneksi.php";
//misal kita mau ambil mata kuliah di semester ganjil
$semester = "3";
echo "MATA KULIAH SEMESTER : $semester<p>";
//melakukan query ke database
$kuliah = mysql_query("select * from makul where SEMES='$semester'");
while($k = mysql_fetch_array($kuliah)){
$kode[] = $k['KDMKM'];
$nama[] = $k['NAKMK'];
$sks[] = $k['SKSMK'];
}
?>
<html>
<head>
<title>Check Box</title>
<script>
<?php
echo "var jumlah = ".count($kode).";\n";
echo "var sks = new Array();\n";
//mengambil sks matakuliah dan memasukkan ke array javascript
for($j=0;$j<count($kode);$j++){
echo "sks['".$kode[$j]."'] = ".$sks[$j].";\n";
}
?>
function hitungtotal(){
jum = 0;
for(i=0;i<jumlah;i++){
id = "mk"+i;
td1 = "k1"+i;
td2 = "k2"+i;
td3 = "k3"+i;
td4 = "k4"+i;
if(document.getElementById(id).checked){
kode = document.getElementById(id).value
jum = jum + sks[kode];
//untuk mengubah warna latar tabel apabila diceklist
document.getElementById(td1).style.backgroundColor = "orange";
document.getElementById(td2).style.backgroundColor = "orange";
document.getElementById(td3).style.backgroundColor = "orange";
document.getElementById(td4).style.backgroundColor = "orange";
}else {
document.getElementById(td1).style.backgroundColor = "white";
document.getElementById(td2).style.backgroundColor = "white";
document.getElementById(td3).style.backgroundColor = "white";
document.getElementById(td4).style.backgroundColor = "white";
}
}
//menampilkan total jumlah SKS yang diambil
document.getElementById("jsks").innerHTML = jum;
}
</script>
</head>
<body>
<form name="formkrs" method="POST" action="index1.php?hal=inputkrs">
<table border=1 width=400 style="border-collapse:collapse" bordercolor="#999999">
<tr><td><b>Kode</b></td><td><b>Nama Mata Kuliah</b></td>
<td><b>SKS</b></td><td><b>Ambil</b></td></tr>
<?php
//menampilkan matakuliah ke dalam tabel
for($i=0;$i<count($kode);$i++){
echo "<tr><td id=k1$i>".$kode[$i]."</td>";
echo "<td id=k2$i>".$nama[$i]."</td>";
echo "<td id=k3$i>".$sks[$i]."</td>";
echo "<td id=k4$i><input type=checkbox name=mk[] onclick=hitungtotal()
value=".$kode[$i]." id=mk".$i."></tr>";
}
?>
<tr><td colspan=3>JUMLAH YANG DIAMBIL</td><td><span id=jsks></span></td></tr>
</table>
<br/>
<input name="kirim" type="submit" value="Kirim KRS">
<input type="reset" >
</form>
</body>
</html>